URL Rewriter.NET and multiple requests

I emphasize trying to create a rewriter.net url rule for my website.

I have a link

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

      

And I want to replace it with

 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 anyone help me?

+2


source to share


5 answers


This will work



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

      

0


source


Try the following:

<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 think that "." you are using too greedy and too much matches.

+2


source


You added:

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

      

to your web.config

file?

0


source


you forgot to escape some special characters ("." and "?") and are not sure about "~":

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

      

0


source


Try the following:

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

      

0


source







All Articles