.htaccess with multi domains
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 have 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
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.
精彩评论