Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite: RewriteCond with multiple RewriteRules

         

thehiatus

4:55 pm on Nov 25, 2003 (gmt 0)



Like most I have a mod_rewrite question. I want to have a RewriteCond affect more than one RewriteRule. For example, if I have something like this:

RewriteCond test match
RewriteRule pattern1 substitution1
RewriteRule pattern2 substitution2

I'd like the pattern2 RewriteRule to run ONLY if the RewriteCond is met, but even if pattern1 is not matched. In other words, I want to do something like this:


if (RewriteCond) {
RewriteRule pattern1...
RewriteRule pattern2...
}

But mod_rewrite only seems to do this:


if (RewriteCond){
RewriteRule pattern1...
}
RewriteRule pattern2...

Do I have to repeat the same RewriteCond (or set of RewriteConds) for each rule? I'd appreciate any help. Thanks.

jdMorgan

9:49 pm on Nov 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thehiatus,

Welcome to WebmasterWorld [webmasterworld.com]!

See the [C] Chain flag for RewriteRule.

Another approach is to force rewriting to stop by detecting the exit case:


RewriteCond <condition to quit under>
RewriteRule .* - [L]
<code for 'else' case goes here>

Jim