如何使.htaccess RewriteCond检查域名? [英] How to make .htaccess RewriteCond check domain name?
问题描述
我有这个规则:
RewriteRule ^(about|installation|mypages|privacy|terms)(/)*$
/index.php?kind=portal&id=1&page=$1&%{QUERY_STRING} [L]
如何更改它,使其仅适用于特定域,例如www.domain.com
?
How can I change it so that it would work only for a specific domain, www.domain.com
for example?
推荐答案
您需要重写条件:
RewriteCond %{HTTP_HOST} ^www.domain.com$
在您的重写规则之前.
如果您在规则之前列出了几个重写条件,则每个条件都必须匹配才能执行RewriteRule,例如:
If you list several rewrite conditions before your rules, everyone of them must match for the RewriteRule to be executed, for example:
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteCond %{HTTP_HOST} ^www.domain2.com$
这当然是行不通的,因为HTTP_HOST不能同时包含两个值.
which will of course NOT work, because the HTTP_HOST cannot contain simultaneously both values.
然后必须使用[OR]修饰符:
You must then use the [OR] modifier:
RewriteCond %{HTTP_HOST} ^www.domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain2.com$
以便在以上任何条件匹配时执行RewriteRule.
so that the RewriteRule is executed if ANY of the above conditions match.
请参见 http://httpd.apache.org/docs/2.0 /mod/mod_rewrite.html#rewritecond 了解更多信息.
这篇关于如何使.htaccess RewriteCond检查域名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!