Loop challenge

Topics: Developer Forum, User Forum
Jan 27, 2008 at 12:26 PM
Hello,

what I am tryng to do is to transform a url like this

ex. www.mydomain.com/office/en-US/mail/var1/result1/var2/result2/var3/result3/ ...

ex. www.mydomain.com/office/en-US/shop/folder/123/category/34/productid/849/ ...

into

www.mydomain.com/default.asp?app=office&lang=en&country=US&service=mail&var1=result1&var2=result2&var3=result3

as you can see in the middle of the URL starts a LOOP and that is the difficult part of the rewriting

I got able to do the first part transforming this
www.mydomain.com/office/en-US/mail/
into
www.mydomain.com/default.asp?app=office&lang=en&country=US&service=mail
thanks to
RewriteRule ^/(office|site|more)/(it|en)-(IT|US)/(^\.\/+)/$ /default.asp?app=$1&lang=$2&country=$3&service=$4

but i am missing the loop part

Does anyone know how to help me?

thanks Ginna
Coordinator
Jan 27, 2008 at 10:18 PM
Have you looked at the tests folder in the IIRF distribution?
There is a directory called TransformUrlSegmentsToQueryParamsIteratively that provides an example of what you are trying to do, I Think.

I have not figured out how to do this in a single rewrite rule. In that test directory, I used a set of rules - one for the initial step (getting the question mark), another rule for all the various pairs of keys+values, and a final rule for the final part of the URL.

have a look and see if that works for you.

 
 
# handle case with no query string .  This rule fires the first time through.
RewriteRule ^/(?!index\.cfm)([^\?\/]+)/([^\?]+)$ /$2?v=$1
 
# handle case with existing query string. This rule fires potentially multiple times.
RewriteRule ^/(?!index\.cfm)([^\?\/]+)/([^\?]+)\?(.+)$ /$2?$3&v=$1
 
# handle case with one more segment. This fires once (last).
RewriteRule ^/(?!index\.cfm)([^\/]+)\?([^\?]+)$ /index.cfm?$2&v=$1  [L]
 
# handle edge case, where there is only one segment. This fires once (last).
RewriteRule ^/(?!index\.cfm)([^\/]+)$ /index.cfm?v=$1  [L]