Rules help .. (iterative)

Topics: User Forum
Oct 2, 2008 at 11:42 PM
Edited Oct 2, 2008 at 11:48 PM
Hello everyone,

i have stumbled on a problem ..

i need to create a rule that (in my understanding) requires an unlimited iteration.. plus some extras :p

what i need to grab is the following:

case 1 : split the folders to querystring parameters (no spaces in there and no special chars)
to become
or if easier ( i will enforce the correct sequence)

case 2 : same as 1 but with an existing querystring after the last /
to become

is that possible ?
and is it understandable ? :)

regards and appreciate any help on this
Oct 3, 2008 at 6:41 AM
Yes it is possible.

Have you looked at the example here: 

Also, I would like you to consider whether you need indexed params (a1=value1&a2=value2...) or whether you can just transform the entire URL into a single query param, eg
is mapped to and then let somepage.asp break up the URL as appropriate.

Finally I suggest you test out your rewrite rules with the testdriver.exe program.  It is very nice for iteratively developing your rules, testing your ideas.  It will give you some good insight into how to  build rewrite rules to suit your purpose.
Oct 4, 2008 at 12:35 AM
Thanks for the link and the idea :)

i will look into them right away..

Oct 4, 2008 at 1:00 AM
Gabriele, I love your name.
Oct 5, 2008 at 9:33 PM
Edited Oct 5, 2008 at 9:36 PM
Hi Cheeso,

i like it too :p , belongs to my grandfather :)

on the issue at hand now ... (hehe)

I have managed to convert everything to querystring handling all cases... (not sure how efficient it is though, not an expert on regexp..)

Here are my rules (after playing with the examples a bit..)
RewriteRule ^/(?!template\.asp)([^\?\/]+)/([^\?]+)$ /$2?v=$1
RewriteRule ^/(?!template\.asp)([^\?\/]+)/([^\?]+)\?(.+)$ /$2?$3&v=$1

RewriteRule ^/(?!template\.asp)([^\?\/]+)\?(.+)$ /template.asp?$2&v=$1    [L]
RewriteRule ^/(?!template\.asp)([^\?\/]+)\/\?(.+)$ /template.asp?$2&v=$1    [L]
RewriteRule ^/(?!template\.asp)([^\?\/]+) /template.asp?v=$1    [L]
RewriteRule ^/(?!template\.asp)\?(.+)$ /template.asp?$1    [L]
I also do not know if i could compact them somehow ..

Anyways, the new problem at hand seems to be that since it redirects everything to /template.asp?.... it also changes the legitimate calls to /skins/whatever.css and /layout/someimage.gif
So i need to somehow exclude a list of (root level) folders from being processed by it..

I have tried with the RewriteCond but have failed every single time ..
Not sure how to approach it .. All examples i have seen use a single rewrite rule, so once a condition is met or not the rule is executed..
but that approach will not work with the iterative and multiple rules i have ..

any insight ?


ps. sorry if you got the initial post .. (i tried to style the rules in word to appear better... and it got messed up..)
Oct 5, 2008 at 10:03 PM
Well.. it seems i overlooked the obvious ...

RewriteRule ^/(layout|skin|font\sfiles)/(.+)$ /$1/$2    [L]

this small line, seems to handle the issue perfectly :)

i would appreciate though a general look at my rules, and some comments if there is something obviously wrong ..

take care, and thanks for the excellent product and support !

Oct 6, 2008 at 9:34 PM

This rule:

RewriteRule ^/(layout|skin|font\sfiles)/(.+)$ /$1/$2    [L]

..says to rewrite the URL (and make it the last rule checked) if the URL matches /layout/whatever or /skin/whatever. The URL is rewritten to ... itself.   It is the same as if the URL had not been rewritten at all.

There is a nice feature in IIRF where you use a dash to specify  "NO REWRITE".  This is better than rewriting the URL to itself, because it eliminates unnecessary memory allocations and copies during the engine execution, and also it can be clearer in the ini file . So your rule would look like this:

# no rewrite at all for these 
RewriteRule ^/(layout|skin|font\sfiles)/(.+)$     -     [L]

The effect is to "filter out" the matched URLs from further processing by the rewrite engine.

You could use the same technique to "filter out" any URLs that match template.asp, like so:

# if it is template.asp, don't rewrite
RewriteRule ^/template\.asp(.+)$     -     [L]

And in that case you don't need the negative lookahead in each of the successive rules. Eg, no need for (?!template\.asp) in each rule.

Oct 6, 2008 at 10:12 PM
I understand Cheeso,

but your proposal does not seem to work ...(the one about the folders)
once i change
RewriteRule ^/(layout|skin|font\sfiles)/(.+)$ /$1/$2    [L]

RewriteRule ^/(layout|skin|font\sfiles)/(.+)$     -     [L]

i lose the css styling .. and the images..

so when no rewrite occurs, the original url is fetched ? (why then is your rule not working ?)

hmm... the plot thickens !
Oct 6, 2008 at 10:18 PM
Whoops - -Gabriele, I think I misled you.
This feature with the no rewrite - it is part of v1.2.15, I believe.

Maybe you are running v1.2.14, in which case, you can just keep the rule you have.
Oct 6, 2008 at 10:24 PM

1.2.14 is what i have.. so this must be it.

odd numbers means unstable/dev version ?
if so i will stick to 1.2.14 for now, and update once stabilized..

thank you for your time.
Oct 7, 2008 at 1:13 AM
No, the odd number on a release of IIRF does not imply unstable.

v1.2.15 is nearing release.