How to make .htaccess RewriteCond check domain name?

喜夏-厌秋 提交于 2019-12-03 09:46:19

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.

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