Q:

Intelligencia UrlRewriter with RegEx is not working

I have the following rewrite rule:
<rewrite url="^/Membership/(.+)/(.+)/(.+)/(.+)" to="/Membership/Index.aspx?parentf=$3&amp;f=$4"/>

which I am expecting should work with this URL:
/Membership/Benefits/Member-Groups/Sub-Groups/Motorcycle-Live.aspx

However, in my page that this rewritten URL maps to (/Membership/Index.aspx), I am retrieving the FileName ("f" in my querystring) and ParentFileName ("parentf" in my querystring) to use in a query to get the current page information.

Value of FileName in this case is Sub-Groups,Motorcycle-Live.aspx (when I was expecting it to just be Motorcycle-Live.aspx)
Value of 'ParentFileName' in this case is Member-Groups (when I was expecting it to be 'Sub-Groups')

I have a few other rewrite rules for lower levels, for example:
<rewrite url="^/Membership/(.+)" to="/Membership/Index.aspx?f=$1"/>
<rewrite url="^/Membership/(.+)/(.+)" to="/Membership/Index.aspx?parentf=$1&amp;f=$2"/>
<rewrite url="^/Membership/(.+)/(.+)/(.+)" to="/Membership/Index.aspx?parentf=$2&amp;f=$3"/>

They would work with the following example URLs (respectively):
/Membership/Benefits.aspx
/Membership/Benefits/Member-Groups.aspx
/Membership/Benefits/Member-Groups/Sub-Groups.aspx

In these cases, the FileName and ParentFileName values are generated as expected. It is only with this '5th-level' page that I am having a problem.
What am I doing wrong?

EDIT
After removing all of the rewrite rules in my web.config except from this one:
<rewrite url="^/Membership/(.+)/(.+)/(.+)/(.+)" to="/Membership/Index.aspx?parentf=$3&amp;f=$4"/>

I found that it worked on its own. Then I tried adding them all back in one by one and changing the order until it worked. I finally found that the following order of rules works:
<rewrite url="^/Membership/(.+)" to="/Membership/Index.aspx?f=$1"/>
<rewrite url="^/Membership/(.+)/(.+)/(.+)/(.+)" to="/Membership/Index.aspx?parentf=$3&amp;f=$4"/>
<rewrite url="^/Membership/(.+)/(.+)/(.+)" to="/Membership/Index.aspx?parentf=$2&amp;f=$3"/>
<rewrite url="^/Membership/(.+)/(.+)" to="/Membership/Index.aspx?parentf=$1&amp;f=$2"/>

So just reversing the order except that I have kept the first rule in the same position.

A:

Instead of all your posted rules, try this:
<rewrite url="^/Membership/([^/]+)$" to="/Membership/Index.aspx?f=$1"/>
<rewrite url="^/Membership/([^/]+/)*([^/]+)/([^/]+)$" to="/Membership/Index.aspx?parentf=$2&amp;f=$3"/>

This should avoid the rule ambiguity, and has a general rule for arbitrary path depth.

