How to make .htaccess RewriteCond check domain name?

二次信任 提交于 2019-12-04 15:42:39

问题


I have this rule:

RewriteRule ^(about|installation|mypages|privacy|terms)(/)*$    
/index.php?kind=portal&id=1&page=$1&%{QUERY_STRING} [L]

How can I change it so that it would work only for a specific domain, www.domain.com for example?


回答1:


You need a rewrite condition:

RewriteCond %{HTTP_HOST} ^www.domain.com$

before your rewrite rule.

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$

which will of course NOT work, because the HTTP_HOST cannot contain simultaneously both values.

You must then use the [OR] modifier:

RewriteCond %{HTTP_HOST} ^www.domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain2.com$

so that the RewriteRule is executed if ANY of the above conditions match.

See http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritecond for more information.



来源:https://stackoverflow.com/questions/10785475/how-to-make-htaccess-rewritecond-check-domain-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!