How to make .htaccess RewriteCond check domain name?

.htaccess, mod-rewrite, url-rewriting

Solution

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.

Problem

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?

Original source