简体   繁体   English

301重定向到特定域

[英]301 redirect for specific domain

I have a setup where two domains share the same .htaccess by adding VirtualHost configuration to one of the domains. 我有一个设置,其中两个域通过将VirtualHost配置添加到其中一个域来共享相同的.htaccess。 The trouble is that if I write a 301 redirect in the .htaccess it applies to both domains. 问题是,如果我在.htaccess中编写了301重定向,则它适用于两个域。

Is there a condition I can put around a redirect to ensure it only applies to a matching domain? 我是否可以绕过重定向以确保它仅适用于匹配的域?

Yes sure you can use a RewriteCond to target only one domain like this: 是的,请确保您可以使用RewriteCond 仅将一个域定位为如下所示:

RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com$ [NC]
RewriteRule ^foo/?$ http://example.com/bar [L,R=301]

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

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