From: Daniel Gruno RewriteRule
immediately
following it. Thus, if you want to make a RewriteCond
apply
to several RewriteRule
s, one possible technique is to
-negate those conditions and use a [Skip] flag. So, you can
+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
+