Since the advent of search engines URL rewriting has become mandatory. It makes URLs look nicer and clearer in terms of what content to expect at the given URL. Recently I uploaded few static HTML files to an IIS site. I wanted a nice looking URL without .html extension which was quite straight-forward to achieve in ASP.NET site. You can install URL Rewrite Module in IIS 7 or above versions and a few configuration steps is all that is required to achieve the desired results.
Read this article from Microsoft to get in-depth understanding of the steps. Below is the sample web.config entry I had to make to achieve the results
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to .html Rule">
<match url="^games/([_0-9a-z-]+)" />
<action type="Rewrite" url="games/{R:1}.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
You will need some understanding of the regular expressions to create a matching pattern for your URL (match tag in web.config) and map it to actual resource on the server which is defined in action tag. Here I am simply looking to match following condition for the URL
- Starts with the sequence of characters “games/”.
- Contains one or more alphanumeric or “_” or “-” characters after the first “/”.
And within 5 mins of effort I had a nice looking SEO friendly URL.