简体   繁体   English

将多个域重定向到一个网址

[英]Redirect multiple domains to one url

Using .htaccess, I need to redirect two domains to a third url for a client. 使用.htaccess,我需要将两个域重定向到客户端的第三个URL。
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? 我应该如何设置它才能使其正常工作?

It's because last rule matches everything even for domain3. 这是因为最后一个规则甚至与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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM