2

I'm stressing 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?

1
  • Why would you want to keep the .aspx? You could make a prettier (and more semantic) url fairly easily with rewriting... Commented Oct 14, 2009 at 21:18

5 Answers 5

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

This will work

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

Comments

0

Did you add:

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

to your web.config file?

Comments

0

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" />

Comments

0

Try this:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.