开发者

URL Rewriter.NET and multiple querystrings

开发者 https://www.devze.com 2022-12-08 18:51 出处:网络
I\'m stressi开发者_运维知识库ng out trying to create a url rewriter.net rule for my web site.

I'm stressi开发者_运维知识库ng out trying to create a url rewriter.net rule for my web site.

I have a link

 http://localhost/Pages/CategoryList.aspx?ID=2&Page=1

And I want replace it by this

 http://localhost/Category/2.aspx?Page=1

I tried the following:

<rewrite url="~/Category/(.+).aspx?Page=(.+)" to="~/Pages/CategoryList.aspx?ID=$1&amp;Page=$2" /> 

But it didn't work.

Can anybody help me?


Try this:

<rewrite url="~/Category/([0-9]+)\.aspx\?Page=([0-9]+)" to="~/Pages/CategoryList.aspx?ID=$1&amp;Page=$2" />

Or better(shorter):

<rewrite url="~/Category/(d+)\.aspx\?Page=(d+)" to="~/Pages/CategoryList.aspx?ID=$1&amp;Page=$2" />

I'm thinking that the "." you're using is too greedy and matches too much.


This will work

<rewrite url="~/Category/(.+).aspx(\?(.*))?" to="~/Pages/CategoryList.aspx?ID=$1&amp;$3" />


Did you add:

<httpModules>
      <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/>
</httpModules>

to your web.config file?


you forgot to escape some special symbols ('.' and '?'), and not sure about the '~':

<rewrite url=".*/Category/(.+)\.aspx\?Page=(.+)" to="/Pages/CategoryList.aspx?ID=$1&amp;Page=$2" />


Try this:

<rewrite url="~/Category/(.+)\.aspx\?Page=(.+)" 
         to ="~/Pages/CategoryList.aspx?ID=$1&amp;Page=$2" />
0

精彩评论

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

关注公众号