Decaflon

Welcome to Decaflon! Where the geeks hang out: Signup or Login Here
Decaflon is proudly hosted by (mt) Media Temple.  We recommend them for your web hosting needs.
Clips: Popular Clips Upcoming Clips Notes: All Notes

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.


RewriteCond %{HTTP_HOST}!^www.domain.com
RewriteRule (.*) http://sub.domain.com/$1 [R=301,L]

Not positive it will work.

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.

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.

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.

Please Login To Leave A Comment

Decaflon Sponsors Get in touch if you want in.

Hot Notes (View all »)

 

Decaflon is part of the Chawlk Network of sites.

9 Great Places To Visit, Hang Out, & Meet New People

What's new and interesting at other Chawlk Network sites: