From: Daniel Gruno Date: Sat, 31 Mar 2012 08:17:05 +0000 (+0000) Subject: Clarify the [Skip] flag and add an if-then-else example X-Git-Tag: 2.2.23~211 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f9934ef56d0233f98676ecb6a22f1de271d0cae3;p=thirdparty%2Fapache%2Fhttpd.git Clarify the [Skip] flag and add an if-then-else example git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@1307737 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/manual/rewrite/flags.xml b/docs/manual/rewrite/flags.xml index 4be92b7dd97..378cd49419f 100644 --- a/docs/manual/rewrite/flags.xml +++ b/docs/manual/rewrite/flags.xml @@ -614,10 +614,30 @@ module="mod_rewrite">RewriteCond only applies to the RewriteRule immediately following it. Thus, if you want to make a RewriteCond apply to several RewriteRules, one possible technique is to -negate those conditions and use a [Skip] flag. So, you can -use this to make pseudo if-then-else constructs: The last rule of -the then-clause becomes skip=N, where N is the -number of rules in the else-clause.

+negate those conditions and add a RewriteRule with a [Skip] flag. You can +use this to make pseudo if-then-else constructs: The last rule of +the then-clause becomes skip=N, where N is the +number of rules in the else-clause:

+ +# Does the file exist?
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteCond %{REQUEST_FILENAME} !-d
+# Create an if-then-else construct by skipping 3 lines if we meant to go to the "else" stanza.
+RewriteRule .? - [S=3]
+
+# IF the file exists, then: + + RewriteRule (.*\.gif) images.php?$1
+ RewriteRule (.*\.html) docs.php?$1
+ # Skip past the "else" stanza.
+ RewriteRule .? - [S=1]
+
+# ELSE... + + RewriteRule (.*) 404.php?file=$1
+
+# END +
T|type