You are viewing a plain text version of this content. The canonical link for it is here.
Posted to docs@httpd.apache.org by Apache Wiki <wi...@apache.org> on 2011/03/11 13:54:12 UTC
[Httpd Wiki] Update of "RewriteCond" by sjorge
Dear Wiki user,
You have subscribed to a wiki page or wiki category on "Httpd Wiki" for change notification.
The "RewriteCond" page has been changed by sjorge.
http://wiki.apache.org/httpd/RewriteCond?action=diff&rev1=2&rev2=3
--------------------------------------------------
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
+ E.g. using
+
{{{
- RewriteCond {HTTP_HOST} !=""
+ RewriteCond %{HTTP_HOST} !=""
+ }}}
- }}} instead of
+ instead of
+
{{{
- RewriteCond {HTTP_HOST} .
+ RewriteCond %{HTTP_HOST} .
# or
- RewriteCond {HTTP_HOST} !^$
+ RewriteCond %{HTTP_HOST} !^$
- }}} or using
+ }}}
- {{{RewriteCond {REQUEST_URI} !=/foo/bar
+ or using{{{RewriteCond {REQUEST_URI} !=/foo/bar }}} instead of
- }}} instead of
+
{{{
- RewriteCond {REQUEST_URI} !^/foo/bar$
+ RewriteCond %{REQUEST_URI} !^/foo/bar$
}}}
- or
- {{{RewriteCond {SERVER_PORT} =443
+ or {{{RewriteCond {SERVER_PORT} =443 }}} instead of
- }}} instead of
+
{{{
- RewriteCond {SERVER_PORT} ^443$
+ 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):
- '''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:
- 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
---------------------------------------------------------------------
To unsubscribe, e-mail: docs-unsubscribe@httpd.apache.org
For additional commands, e-mail: docs-help@httpd.apache.org