Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Httpd Wiki" for change 
notification.

The following page has been changed by RichBowen:
http://wiki.apache.org/httpd/RewriteCond

New page:
The '''RewriteCond''' directive defines conditions under which the rewriting 
should take place.

== Syntax ==

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]
}}}

== Examples ==
See ConditionalRewrites

Reply via email to