Help with this (simple) regular expression...?
I'm using URL rewriting with my APS.NET application and haven't had much l开发者_StackOverflowuck matching the following regular expressions...
<rewrite url="~/deals/(.+)$" to="~/Deals.aspx?deal_string=$1" />
<rewrite url="~/deals/(.+?)/edit$" to="~/EditDeals.aspx?deal_string=$1" />
I'm wanting a separate page for viewing a 'deal' to editing a 'deal'. I would like the URL to simply add '/edit' to a deal to go to the Edit Deal page.
Currently, all traffic goes to the first page.
The problem is that any url that matches the second one also matches with the first on (with a different $1 capture). Perhaps if you invert the sequence of declarations it will work. If the second and most specific is evaluated first it should do the job.
Also you could rewrite your expressions avoiding slash characters among your capture.
<rewrite url="~/deals/([ˆ/]+)$" to="~/Deals.aspx?deal_string=$1" />
<rewrite url="~/deals/(.+?)/edit$" to="~/EditDeals.aspx?deal_string=$1" />
The charset [ˆ/] means any char but /. The way the 1st expression would no longer match /deals/hello/edit.
精彩评论