2

I have a url that can look like

domain.com/f1/v1/f2/v2/f3/v3/f4/v4/f5/v5/f6/v6

with variations of lesser counts such as

domain.com/f1/v1/f2/v2/f3/v3/f4/v4/f5/v5
domain.com/f1/v1/f2/v2/f3/v3/f4/v4
domain.com/f1/v1/f2/v2/f3/v3
domain.com/f1/v1/f2/v2
domain.com/f1/v1

how can i build a rewrite rule that will construct the following

domain.com/models?f1=v1&f2=v2...f6=v6

this website is an IIS 6 MVC 3 application using Helicon Isapi_Rewrite for url rewrites.

jason
  • 767
  • 2
  • 9
  • 24
  • I don't know how to do it in Helicon, but IIRF includes examples for transforming query-string params into url path segments, and vice versa. You may be able to take those examples and apply them to Helicon, or just use IIRF. http://cheeso.members.winisp.net/Iirf21Help/html/1ccbf1ec-0984-49d9-9ab0-63eab3ff9c63.htm – Cheeso Jul 02 '12 at 23:00
  • why don't you use mvc's built in URL routing engine? – Muhammad Adeel Zahid Jul 03 '12 at 09:25

2 Answers2

0

The best way is to create a set of rules each rule will process 1 pair, 2 pairs, 3 pairs of paraters...

RewriteEngine on
RewriteBase /

# rule for one pair of parameters
RewriteCond %{HTTP:Host} ^domain\.com$ [NC]
RewriteRule ^([^/]+)/([^/]+)$ /models?$1=$2 [NC,L]

# rule for two pairs of parameters
RewriteCond %{HTTP:Host} ^domain\.com$ [NC]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)$ /models?$1=$2&$3=$4 [NC,L]
Andrew
  • 511
  • 3
  • 7
0

I came up with this solution using a map. The main problem I had was exceeding the $1-$9 limitation on placeholders.

RewriteMap filtermap txt:content/maps/filtermap.txt [NC]

RewriteCond ${filtermap:$6|NOT_FOUND} !NOT_FOUND  [NC]
RewriteRule ^models/([^/]*/[^/]*)/([^/]*/[^/]*)/([^/]*/[^/]*)/([^/]*/[^/]*)/([^/]*/[^/]*)/([^/]*/[^/]*)   /models/?${filtermap:$1}&${filtermap:$2}&${filtermap:$3}&${filtermap:$4}&${filtermap:$5}&${filtermap:$6} [NC,L]

RewriteCond ${filtermap:$5|NOT_FOUND} !NOT_FOUND  [NC]
RewriteRule ^models/([^/]*/[^/]*)/([^/]*/[^/]*)/([^/]*/[^/]*)/([^/]*/[^/]*)/([^/]*/[^/]*)                 /models/?${filtermap:$1}&${filtermap:$2}&${filtermap:$3}&${filtermap:$4}&${filtermap:$5} [NC,L]

RewriteCond ${filtermap:$4|NOT_FOUND} !NOT_FOUND  [NC]
RewriteRule ^models/([^/]*/[^/]*)/([^/]*/[^/]*)/([^/]*/[^/]*)/([^/]*/[^/]*)                               /models/?${filtermap:$1}&${filtermap:$2}&${filtermap:$3}&${filtermap:$4} [NC,L]

RewriteCond ${filtermap:$3|NOT_FOUND} !NOT_FOUND  [NC]
RewriteRule ^models/([^/]*/[^/]*)/([^/]*/[^/]*)/([^/]*/[^/]*)                                             /models/?${filtermap:$1}&${filtermap:$2}&${filtermap:$3} [NC,L]

RewriteCond ${filtermap:$2|NOT_FOUND} !NOT_FOUND  [NC]
RewriteRule ^models/([^/]*/[^/]*)/([^/]*/[^/]*)                                                           /models/?${filtermap:$1}&${filtermap:$2} [NC,L]

RewriteCond ${filtermap:$1|NOT_FOUND} !NOT_FOUND  [NC]
RewriteRule ^models/([^/]*/[^/]*)                                                                         /models/?${filtermap:$1} [NC,L]

Its not super pretty but it does work. The filter map looks like this

    p1/v1  p1=v1
    p2/v2  p2=v2
...

This is not an ideal solution if your combinations of p1/v1 are unlimited, but mine are finite so its pretty easy to manage.

jason
  • 767
  • 2
  • 9
  • 24