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?
htaccess rewrite rules can be used to direct requests for one subdirectory to a different location, such as an alternative subdirectory or even the domain root. In this example, requests to http://mydomain.com/folder1/ will be automatically redirected to http://mydomain.com/folder2/.
The [NC] specifies that the http host is case insensitive. The escapes the "." - because this is a special character (normally, the dot (.) means that one character is unspecified). The final line describes the action that should be executed: RewriteRule ^(.*)$ http://www. example.com/$1 [L,R=301]
RewriteRule is used to rewrite the url as the name signifies if all the conditions defined in RewriteCond are matching. One or more RewriteCond can precede a RewriteRule directive. If we talk about traditional programming RewriteCond works just like 'If' condition where you can use conditions like AND, OR, >=, == , !
mod_rewrite is an Apache module that allows for server-side manipulation of requested URLs. mod_rewrite is an Apache module that allows for server-side manipulation of requested URLs. Incoming URLs are checked against a series of rules. The rules contain a regular expression to detect a particular pattern.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With