How to run one rewrite rule only once?

Topics: Developer Forum, User Forum
Jul 21, 2008 at 10:01 AM
Hi guys.

I am wondering if it is possible to run a rule only once. I have multiple rules, and some of them (those who replace characters for example) need to be recursive. Therefore I can't just set IterationLimit to 1. But I have one rule that must not be recursive, it's the following:

RewriteRule ^(?:/*(?:1/([^/]+))*)(?:/*(?:2/([^/]+))*)(?:/*(?:3/([^/]+))*)(/*.*)$ what=$1&where=$2&id=$3$4 [I]

This would be used to rewrite this:

into this:

But, if this is recursive, it will be hit again and again, because of the last numbered group (/*.*). And the result will be:
Incoming 1:
Output/incoming 2:
Output/incoming 3:
Output/incoming 4:
...and so on until IterationLimit is reached.

This is no good of course. Any ideas on how to solve this? I'm open for all suggestions.

Thanks in advance.
Jul 22, 2008 at 1:07 AM
Edited Jul 22, 2008 at 1:08 AM

how about a negative lookahead in the regex?  eg, "Only rewrite if the what=xxx is NOT already set. "

Your negative lookahead might be like this:  (?!what=[^&]+)  , which you will need to embed at the proper place in the regex.

There are example negative lookaheads here:

You can test out variations of regex's with the testdriver.exe tool.