.htaccess redirect help needed
Written By seanrox on Jun. 14, 2007.
4 Comments
Report Note
+ Clip This
It's been a long week and it's only Wednesday and my brain is moosh.
I need some help coming up with code for a .htaccess file to 301 redirect any page from a main domain name to a sub domain.
Example, I want all pages from www.domain.com to be 301 redirected to sub.domain.com
Basically I'm trying to move a complete site into a sub domain and don't want to loose the seo for the pages.
I hope that makes sense... again, I'm tired.
I'm thinking something like this:
RewriteEngine On
RewriteRule ^/(.*) http://sub.domain.com/$1 [QSA,R=301,L]
Any help would be great. Thanks in advance.

Scrivs
Written Jun. 14, 2007 / Report /
RewriteCond %{HTTP_HOST}!^www.domain.com
RewriteRule (.*) http://sub.domain.com/$1 [R=301,L]
Not positive it will work.
seanrox
Written Jun. 14, 2007 / Report /
Thanks Scrivs. It looks right. I'll try it out in the AM once I've had a little sleep and let you know how it pans out.
Griffin
Written Jun. 14, 2007 / Report /
Hey Sean, I moved my site two or three months back (to a subdomain) and ended up using this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^NAME.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.NAME.com$
RewriteRule ^(.*)$ http://sub.domain.com [R=301,L]
I certainly did not come up with it, and I can't recall where I snatched it from, but it was after much trolling for an answer. Worked out for me, though I can't say I'm privy to all the magic it weaves, or if there's better to be found.
seanrox
Written Jun. 14, 2007 / Report /
Hi Griffin.
I looked at your site and how you have it working, so I think your solution will do exactly what I'm needing but like the suggestion of Scrivs, I'll try it in the morning.
Thanks for your suggestion.