Reputation: 7035
Using .htaccess, I need to redirect two domains to a third url for a client.
Redirecting one to another works without any issues:
RewriteCond %{HTTP_HOST} =domain1.com
RewriteCond %{HTTP_HOST} =www.domain1.com [OR]
RewriteRule ^(.*)$ http://domain2.com/$1 [R=301,L]
But if I take the same approach for multiple domains I end up with a redirect loop -
RewriteCond %{HTTP_HOST} =domain1.com
RewriteCond %{HTTP_HOST} =www.domain1.com [OR]
RewriteCond %{HTTP_HOST} =domain2.com [OR]
RewriteCond %{HTTP_HOST} =www.domain2.com [OR]
RewriteRule ^(.*)$ http://domain3.com/$1 [R=301,L]
How should I set this up in order for it to work properly?
Upvotes: 1
Views: 323
Reputation: 1309
It's because last rule matches everything even for domain3. You should cut redirects for it by the condition:
RewriteCond %{HTTP_HOST} (www.)?domain1.com [OR]
RewriteCond %{HTTP_HOST} (www.)?domain2.com
RewriteCond %{HTTP_HOST} !(www.)?domain3.com
RewriteRule ^(.*)$ http://domain3.com/$1 [R=301,L]
Upvotes: 1