Forum Moderators: phranque

Message Too Old, No Replies

Redirecting users to the proper subdomain

         

ocon

4:42 am on Jul 11, 2010 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hello,

I have multiple domain names pointing to one folder on my sever.

So users going to:

example.com
example.net
example.org

All see the same content.

In the past I've used the following entry into my .htaccess file to make the browsers all redirect to one domain:

RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule (.*) [example\.com...] [R=301,L]

My problem is, I now have multiple subdomains on my site, and I need to make it so the redirect accounts for the subdomain.

How can I adjust my code so that users go from:

this to => that

example.net => example.com
www.example.net => www.example.com
test.example.org => test.example.com
example.com => example.com
www.example.com => www.example.com

jdMorgan

9:36 pm on Jul 11, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




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

or, if you still want www-example.xyz => example.com as it was before, use:

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

Jim