Well, URL Redirect, which is mostly used in PHP for making user friendly urls is supported by IIS but with a twist, at least in IIS7.

I banged my head for a couple of hours and for some reason I could not make it work. Lastly I decided to google for url rewrite AND IIS7. To my surprise there is an additional step to be done when registering your HttpModule (the one that will handle the url rewriting). You not only need to add it to the modules tag of the web.config, but also to the <system.webServer> modules tag. See example below (of course this is a stripped down code, you have to intertwine it with your existing web.config)

<system.web>
    <httpModules>
        <add name=UrlRewriter type=Rewrite, UrlRewriter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null />
    </httpModules>

</system.web>
<system.webServer>
    <validation validateIntegratedModeConfiguration=false />
    <modules>
        <add name=Rewriter type=UrlRewriter.Rewrite preCondition=managedHandler />

    </modules>
</system.webServer>

Lots of thanks to Scott Guthrie for his article on url rewriting in asp.net: http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

and also to Denis van der Stelt for his observations on IIS7 and url rewriting: http://bloggingabout.net/blogs/dennis/archive/2006/11/29/IIS7-and-Url-Rewriting.aspx 

07-03-2008
Yesterday I had to upload to a hoster a website using the above technique and it would not work. The hosting was using IIS6, so the ASP.Net would look at <system.web><httpModules> for additional modules, whereas IIS7 would not take into account that, but the settings in <system.webServer>. So what was wrong? The application complained that it could not load the type Rewrite. So I had a closer look and … I wrote the declaration wrong :(. Below you will find the correct add declaration to be added in httpModules:

<add name=UrlRewriter type=UrlRewriter.Rewrite, UrlRewriter, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null />

One Response to “Url Redirect and IIS7”

  1. john says:

    I like it and the background and colors make it easy to reado

Leave a Reply