views:

25

answers:

1

i have this .htaccess rule

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

and right now i hav this code

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

the problem is right now if i type www.domain1.com its return to domain1.com and not www.domain2.com

i will have it to if i type www.domain1.com, domain1.com or domain3.com its will return to this domain ( www.domain2.com ) and if i type ( domain2.com ) its return to www.domain2.com

i hob i can be help here tanks a lot.

A: 

You just need this rule:

RewriteCond %{HTTP_HOST} !=example.com
RewriteRule ^ http://example.com%{REQUEST_URI} [L,R=301]

This will redirect any request to a host that’s not example.com to example.com.

Gumbo