views:

114

answers:

3

Hi all,

I want to implement url-rewrite into an webapplication with the urlrewriter.net module.

This is my scenario now (numbers are fictional): Browse.aspx?cid=9&countryid=85 (cid stands for category id)

Now I want something like this categoryname/countryname.html

So i figured this might work but it doesn't. Its my first time using this i must be missing something.

<rewrite url="~/(.+)/(.+).html" to="~/Browse.aspx?cid=$1&amp;countryid=$2" />

Maybe I need to use the title instead of the id on $1 and $2 but then it would be a lot harder to query things i suppose? And it means alot of rebuilding in the application

Can someone please help me get my head together for this?

Kind regards and thank you for reading, Mark

+1  A: 

It looks like your example would rewrite ~/9/85.html into Browse.aspx?cid=9&countryid=85

I suspect you're looking for something more friendly.

To solve this, give some thought to how you will be generating the *.html URLs in your pages. You could embed the category and country names there, and then just ignore them when you do the URL rewriting.

RickNZ
A: 

You're going to have to lookup the id's on your page with the way that you're doing it right now. Meaning /mycategory/us.html is going to turn into browse.aspx?cid=mycategory&countryid=us

There are two solutions.

1) Pass in the country and category NAMES and do a look up in your DB in browse.aspx

2) Add the id's to the url. Something like http://www.mysite.com/1/2/mycategory/us.html. The web.config setting would be:

<rewrite url="~/(\d+)/(\d+)/(.+)/(.+).html" to="~/Browse.aspx?cid=$1&amp;countryid=$2" />

Hope that helps.

Chris Rock
A: 

Hello Mark

Probably, a request just can't reach urlrewriter.net module because IIS treats it as the request to certain file, not to ASP.NET. You may find helpful the following article: http://www.codeproject.com/KB/aspnet/iis-aspnet-url-rewriting.aspx

Alex Ustinov