Forum Moderators: phranque
I have a RewriteCond that controls whether I want a RewriteRule to take place - it makes sure image links and the css link don't break.
Problem is, I'm going to move towards using multiple rewrite rules for this particular rewrite, so that I can use a variable number of variables in the URI.
What I'm asking is, can I do something like
RewriteCond Cond [flag]
{
RewriteRule1
RewriteRule2
RewriteRule3
....
}
And have a single RewriteCond apply to all the rules? (braces shown just to indicate grouping, I'm aware there is no such syntax in htaccess :) )
Or am I left with no choice but to do this:
RewriteCond Cond [flag]
RewriteRule1
RewriteCond Cond [flag]
RewriteRule2
RewriteCond Cond [flag]
RewriteRule3
RewriteCond Cond [flag]
....
Any ideas? I've read the mod_rewrite documentation but it doesn't address this issue. I'm thinking I might be able to use RewriteMap in some way, but it doesn't address that issue at all and the documentation's description of RewriteMap is less than enlightening.
Added:
Quick note, I just commented out that rewrite Cond and it left my image and css links still working, which didn't work before so I think one of my later changes fixed that problem. So I don't need to immediately address this problem. The rest of my question remains though.
Here is what I was using:
# If the url isn't an image or the css file
RewriteCond %{REQUEST_URI}![a-zA-Z0-9]\.gif¦jpg¦css$# Rewrite the url to the dynamic query string
RewriteRule ^([^/]+)/$ $1.php [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)?/?([^/]+)? $1.php?id=$2&gal=$3&page=$4 [L]
Detect the false case of the original RewriteCond and terminate mod_rewrite processing:
RewriteRule \.(gif¦jpg¦css)$ - [L]
RewriteRule (whatever rules you want for non-image/css files go here)
Use the [S] (skip) flag to accomplish the same thing for that particular ruleset, but continue processing subsequent rules:
RewriteRule \.(gif¦jpg¦css)$ - [[b]S=3[/b]]
RewriteRule (rule #1 you want for non-image/css files goes here)
RewriteRule (rule #2 you want for non-image/css files goes here)
RewriteRule (rule [b]#3[/b] you want for non-image/css files goes here)
#
RewriteRule (this rule will be processed for all gif, jpg, and css files, or if all of the above 3 rules fail to match.)
Very often, a problem that seems impossible to solve becomes possible by using negative logic -- by changing from "do something if condition" to "do something if not condition, or to "don't do something if condition."
Jim