Home >
Blog > Eliminate the default doc name in URLS with IIS7 and URL Rewrite
Posted By:
John,
16 February 2011
ASP.NET, for all of it's wonder has a habit of throwing a spanner in the works.
Until the relatively recent launch of URL Rewrite Module for IIS7, it wasn't easy to get pages that were linked to as "domain.com\default.aspx" to redirect users to "domain.com".
Why do we want to redirect users from "domain.com\default.aspx" to "domain.com".
Good question! We want to make sure that each page has a single, unique address. This means no duplication of data across numerous pages, so search engines (in particular) recognise the value of that page - plus it makes understanding analytics data much easier.
The easy solution
Microsoft have given us a solution - a module that takes no more than a minute to download and install on a webserver and is easily defined in your web.config to do exactly what we want.
The URL Rewrite Module
You can find out more info on the URL Rewrite Module at iis.net URL Rewrite
or download here:
x86 version of the URL Rewrite module
x64 version of the URL Rewrite module
The Code
This is for your web.config file.
<system.webServer>
<rewrite>
<rules>
<rule name="Strip Default.aspx Out">
<match url="(.*)default.aspx" ignoreCase="true" />
<action type="Redirect" url="{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>