Forum Moderators: phranque

Message Too Old, No Replies

Getting 1 RewriteCond to apply to multiple RewriteRules

Is it possible?

         

whoisgregg

4:25 pm on Jul 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a handful of RewriteRules that all have the same RewriteCond preceding them.

I'd like to remove the clutter of:

RewriteCond ....
RewriteRule ....
RewriteCond ....
RewriteRule ....
RewriteCond ....
RewriteRule ....
etc.

Any way to do that? I read through the manual [httpd.apache.org], but didn't see anything that looked helpful.

RonPK

5:58 pm on Jul 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you tried to experiment with leaving out the L flag? That should make the rewrite engine carry on until there are no more rules. As the manual says: "The URL is completely replaced by the Substitution and the rewriting process goes on until there are no more rules unless explicitly terminated by a L flag - see below."

Note that it is not recommended to experiment with mod_rewrite on a production server :-)

jdMorgan

10:20 pm on Jul 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A RewriteCond applies only to the single rule that follows it. However, see the 'Skip' flag:


# If condition NOT true
RewriteCond [b]![/b]<condition>
# Then skip next 5 rules
RewriteRule .* - [S=5]
#
# The following 5 rules will be executed only if the original condition was true
RewriteRule ....
- 3 more -
RewriteRule ....
#
# Processing resumes here if the original condition was not true

Jim

whoisgregg

8:54 pm on Jul 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Works like a charm on my development server, thanks! :)

Should I expect that using the "skip" flag will require a dramatically different amount of time for each request?