Akshay J
Akshay J

Reputation: 5458

Rewrite URL in ASP.NET

I am looking for a rewrite URL tag for such conversion

www.example.com/subject.aspx?subject=aa&page=1

to

www.example.com/subjects/aa/1

I tried to add 2 dollars but it showed error in visual studio and it does not let me compile the solution.

Upvotes: 0

Views: 265

Answers (2)

tetris
tetris

Reputation: 4362

Maybe it's because you're using "/" in your rewrite rule so it creates "virtual directories", one way to bypass this is by using html tag base href.

Upvotes: 0

Pol
Pol

Reputation: 5134

Try this:

<rewrite url="^~/subjects/([A-Za-z]+)/([0-9]+)$" to="~/subject.aspx?subject=$1&amp;page=$2"/>

Upvotes: 3

Related Questions