I have a requirement to rewrite URL's from an older version of my site to the format of the new version:
Old: /param1/param2/param3/param4/param5
New: /param3/param4/param5?a=param1&b=param2
The requirements for pattern matching are that param2 should be only numbers and that params 3-5 are optional.
I came up with this rule:
<match url="([^/]+)/([0-9]+)/?([^/]+)/?([^/]+)/?([^/]+)/?([^/]+)/" />
<action type="Redirect" url="{R:3}/{R:4}/{R:4}?a={R:1}&b={R:2}" />
Which works OK if all params are present but if they aren't it breaks it. Examples:
/hello/world = ?a=hello&b=world
/hello/world/foo = foo?a=hello&b=world
/hello/world/foo/bar = foo/bar?a=hello&b=world
/hello/world/foo/bar/test = foo/bar/test?a=hello&b=world
Is this possible with URL Rewrite?