The RewriteCond directive defines conditions under which the rewriting should take place.


We should really encourage people to use the lexicographically equal operator instead of a RegEx if they want to ckeck, if test string is lexicographically equal to cond pattern.

E.g. using

RewriteCond %{HTTP_HOST} !=""

instead of

RewriteCond %{HTTP_HOST} .
# or
RewriteCond %{HTTP_HOST} !^$

or using RewriteCond {REQUEST_URI} !=/foo/bar  instead of

RewriteCond %{REQUEST_URI} !^/foo/bar$

or RewriteCond {SERVER_PORT} =443  instead of

RewriteCond %{SERVER_PORT} ^443$

Note: Conditions are being processed after the pattern of the RewriteRule has matched. This means that the Condition in following example would be useless (it's always true):

RewriteCond %{REQUEST_URI} \.html$
RewriteRule \.html$ - [G]

While this one wastes performance:

RewriteCond %{REQUEST_URI} ^/([^.]*)\.html$
RewriteRule ^/(.*) /%1.php [PT]

Every Request matches the rule-pattern and after that the condition will be checked. But you can easily check the uri value in the rule-pattern, so that there is no need for such a condition here:

RewriteRule ^/([^.]*)\.html$ /$1.php [PT]


See ConditionalRewrites

RewriteCond (last edited 2011-10-01 08:11:46 by 177-173-33-178)