homepage Welcome to WebmasterWorld Guest from 54.196.206.80
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Accredited PayPal World Seller

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
.htaccess to redirect /directory/ to subdomain
Andrea Wasik




msg:4116293
 11:54 am on Apr 15, 2010 (gmt 0)

I had to move my blog from

www.me.com/blog

to

blog.me.com

How do I make all the files in the /blog directory redirect to the new subdomain, where they are not in a subdirectory.

Thanks!

 

jdMorgan




msg:4116322
 1:30 pm on Apr 15, 2010 (gmt 0)

Hi Andrea, and welcome to WebmasterWorld!

Because we have a limited number of contributors and lots of requests for answers here, we ask that you post your best-effort code and ask very specific questions.

It is important for the proper functioning of your site and for your ability to maintain it, that you completely understand any server configuration code (like code in .htaccess) that you put on your server. Time spent learning about .htaccess modules and their directives is a very wise investment, since one single typo or small logical error can take your site site off-line -- or silently ruin your search engine rankings over time.

This previous thread [webmasterworld.com], along with the resources cited in our Apache Forum Charter and the examples and tutorials in our Apache Forum Library, will help you get started.

Jim

Andrea Wasik




msg:4116484
 6:19 pm on Apr 15, 2010 (gmt 0)

Hi Jim,

This is what I have tried:

RewriteEngine ON
RewriteRule (.*)\.*$
http://blog.example.com/ [R=301,L]

But I can't get it to stop adding the /blog/ directory name to the end of the URL when it redirects it. The old URL was in a /blog/ subdirectory, but now the root of the blog is just blog.example.com

If anyone could provide help, I would appreciate it, I have read a bunch of the tutorials available however this situation doesn't seem to be covered.

Thanks!

[edited by: jdMorgan at 11:33 pm (utc) on Apr 15, 2010]
[edit reason] Please use example.com only. [/edit]

jdMorgan




msg:4116656
 12:18 am on Apr 16, 2010 (gmt 0)

You need a back-reference, and "blog/" must be excluded from that back-reference.

Assuming that this code goes into your top-level .htaccess file, you'll need something like:

RewriteEngine on
#
RewriteRule ^blog/(.*)$ http://blog.example.com/$1 [R=301,L]

Here, the requested URL-path must start with "blog/" to invoke this rule, otherwise it is ignored. Anything following "blog/" is matched by the "match anything, everything, or nothing" subpattern of ".*" and since that subpattern is enclosed in parentheses, whatever matches this subpattern in the requested URL-path will be copied into mod_rewrite's local variable $1. We then redirect to the subomain, appending the contents of $1, and using a 301-Moved Permanently redirect status response. Because we wish mod_rewrite to take no more action after this rule is invoked, we end processing with an [L] flag.

See the resources cited in our Apache Forum Charter for more information.

Jim

Andrea Wasik




msg:4116820
 11:18 am on Apr 16, 2010 (gmt 0)

Thanks Jim!

I also had to add another rule that would rewrite any requests specifically for blog.html, which was the blog home page on the original setup, whereas the new home page is just blog.example.com/ - so I got that to work - see I'm learning already!

Andrea

jdMorgan




msg:4116978
 4:17 pm on Apr 16, 2010 (gmt 0)

... and that is our purpose, here.

I'm glad that you got it sorted. :)

Jim

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved