Forum Moderators: phranque

Message Too Old, No Replies

Redirect all domain aliases to main domain?

         

georgec

9:59 pm on Dec 30, 2009 (gmt 0)

10+ Year Member



Hi:
I'm looking to redirect all domain aliases of our site to the primary domain, obviously honoring any query strings, sub paths etc. However, I also wish to honor the presence of "www" or lack thereof entered into the alias, which the code below doesn't do:


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

How can I get the redirect to check whether the alias entered contains the "www" part, and redirect to the exact same version on the main domain?

Thanks!

g1smd

8:28 am on Dec 31, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Does
example.com
and
www.example.com
serve the same content?

If they do, you should redirect all requests to the www version, so as to avoid this Duplicate Content issue.

jdMorgan

9:48 pm on Dec 31, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the www and non-www contain different content, then

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

should do.

Jim