Within Apache HTTPD’s mod_rewrite, RewriteCond only applies one RewriteRule that comes immediately after the RewriteCond itself. It didn’t seem like such a great idea to have to duplicate a lengthy RewriteCond definition half a dozen times for multiple RewriteRules.
Turns out there is a fairly simple trick to achieve exactly what I was looking for: if the RewriteCond is negated and followed by RewriteRule . – [S=n] to skip the following n rules, the RewriteRules in essence are only applied when the singular RewriteCond is true. Like so:
|
1 2 3 4 5 |
RewriteCond %{REQUEST_URI} !^/(pattern1|pattern2|pattern3)/$ [NC] RewriteRule . - [S=3] RewriteRule ^/pattern1/$ /someURL.php [L] RewriteRule ^/pattern2/$ /someURL2.php [L] RewriteRule ^/pattern3/$ /iLikeDoughnuts.php [L] |
Now the last three rules are skipped if the condition is not true or, in reverse, they are applied if the condition is true. Each pattern is then handled individually, and the [L] rewrite option will cause only the pertinent rule to be applied - processing will stop after the first matched condition.