Forum Moderators: phranque
RewriteCond %{HTTP_USER_AGENT}!Slurp
RewriteRule (.*)oddkw1oddkw2_.+\.htm$ $1oddkw1-oddkw2-$2\.htm [R=301]
RewriteCond %{HTTP_USER_AGENT}!Slurp
RewriteRule (.*)foo1_foo4_.+\.htm$ $1foo1-foo4-$2\.htm [R=301]
... and 50 more in this style. This works of course very well. My question: Is there any way to "link" the RewriteRules together, so that I need only one RewriteCond, but all Rules only work under that condition? All I tried did not work. I mean: if not Slurp then redirect oldfile1 to newfile1 and oldfile2 to newfile2 and ...
Your help is much appreciated. Perhaps, or most likely, the question is dumb.
See the [S] flag to skip over a block of RewriteRules. You could use it like this:
# Skip next 20 rules if Slurp
RewriteCond %{HTTP_USER_AGENT} Slurp
RewriteRule .* - [S=20]
# Do rewrites for all but Slurp
RewriteRule <first rule for non-Slurp UA's
RewriteRule <18 more rules for non-Slurp UA's
RewriteRule <last rule for non-Slurp UA's
# Slurp skips the 20 rules above, and mod_rewrite parsing resumes here
#
# Skip next 32 rules if not Slurp
RewriteCond %{HTTP_USER_AGENT}!Slurp
RewriteRule .* - [S=32]
# Do rewrites for Slurp
RewriteRule <first rule for Slurp
RewriteRule <30 more rules Slurp
RewriteRule <last rule for Slurp
# Non-slurp UA's skip the 30 rules above, and mod_rewrite parsing resumes here.
#
<Remaining rules for non-redirected URLs.>
(If you want to get tricky, you can actually skip 21 rules in the first section, since you don't need to re-test the User-agent in the second section once you know it's Slurp. If this isn't clear, then don't worry about it.)
Jim