IIS7 URL Rewrite

Posted by: Matthew on Wednesday, April 28, 2010

I figured out how to do this today, it’s super simple so I though I’d share how you can do it.

Basically we’re going to make some changes in the web.config file, you need to make sure that IIS7 has the URL Rewrite module installed or else this wont work, I use the Rackspace Cloud and it is installed there by default.

We are going to use the following example:

http://www.domain.com/article.aspx?id=1?title=urlRewrite

rewritten to become:

http://www.domain.com/article/1/urlRewrite

web.config

Place the following between the <system.webServer> </system.webServer> section of your web.config file:

<rules>
       <rule name="Article URLS">
         <match url="article^([0-9]+)/([_0-9a-z-]+)"/>
         <action type="Rewrite" url="article.aspx?id={R:1}&amp;title={R:2}"/>
       </rule>
</rules>

And it’s done, it is really that easy.

Now all you need to do is edit your application so that it spits out the new URL format, unlike LinkFreeze you have to do it all manually.

I hope that helps people who are looking for a simple example some of the official stuff is confusing.

Read More
blog comments powered by Disqus