开发者

URL Rewriter not grabbing the exact match

开发者 https://www.devze.com 2022-12-12 06:06 出处:网络
I\'m implementing some url rewriting using UrlRewriter. So going to http://domainname/11 will go to ~/Items/Details.aspx?Itemid=11

I'm implementing some url rewriting using UrlRewriter.

So going to http://domainname/11

will go to ~/Items/Details.aspx?Itemid=11

  <rewriter>
    <rewrite url="~/1" to="~/Items/Details.aspx?ItemId=1" />
    <rewrite url="~/2" to="~/Items/Details.aspx?ItemId=2" />
    <rewr开发者_StackOverflow中文版ite url="~/3" to="~/Items/Details.aspx?ItemId=3" />
    <rewrite url="~/11" to="~/Items/Details.aspx?ItemId=11" />
  </rewriter>

The problem here is 11 always redirects to 1. Same as 400 redirects to 4. I'm guessings it's not doing an exact match, only some sort of "Contains".

How do I get this to do exact matching?

I was using this for regex to not hard code everything but that didnt work eitehr:

<rewriter>
    <rewrite url="~/(\d)" to="~/Items/Details.aspx?ItemId=$1" />
</rewriter>

thanks guys!


You should specify end of the URL and use a quantifier for your \d expression to allow more than one digit:

<rewriter>
    <rewrite url="~/(\d+)$" to="~/Items/Details.aspx?ItemId=$1" />
</rewriter>


<rewrite url="~/(\d+)" to="~/Items/Details.aspx?ItemId=$1" />
-------------------^
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号