Easy URL Rewrite in IIS

URL rewriting is a process of shortening URL of web pages and making them more user friendly. If you have been working with MVC then you probably already know what I am talking about. But what to do if your application is plain old Web application?  Having user friendly URL really simplifies things for end users. Imagine a product URL for your company is http://someCompany/Products/list/ProductName.aspx , which is definitely not helpful to customer who is trying to reach to that product page directly (only way probably is to create a link on some page). But with help of URL Rewrite you can shorten this URL to http://someCompany/Products/ProductName a user friendly URL, isn’t it ? Besides having good lookin’ URL another advantage is it hides actual directory structure from outside world.

In this post I am going to show how easy it can be to use this great little module.

First, if you don’t have this module it can be downloaded from IIS website or using Web PI (if you have downloaded Web PI before then chances are you already have it). Once it is installed, you will see it in IIS Manager (see screenshot below)

 

URL_Rewrite_1

For this blog post, I have created a simple HTML page have it placed in root directory of IIS C:\inetpub\wwwroot\test.html . Now if you open up this page in browser, URL will look something like this .. http://localhost/test.html

URL_Rewrite_2

To modify this URL, open up URL Rewrite module. In the right hand top corner there is an option to create new rule, click on it. This will open up a page to create new rule. Now, we want to create a rule for both inbound and outbound requests so I will just go with “Inbound and Outbound Rule” –> “User-Friendly URL”. This will open a configuration page to create User Friendly URL. In that page just copy current URL into textbox and you will see that it will generate new URL sample for you ! (when this rule is created for first time there is no way to modify the pattern for URL, but once rule is saved it can be changed to anything we want). Also make sure to check options to create redirect rule and outbound rewrite rule automatically.

URL_Rewrite_3 URL_Rewrite_4 URL_Rewrite_5

 

And that’s it !! Now if you try to browse to that same page, it will show URL as http://localhost/test

URL_Rewrite_6

Pretty cool huh ?

Well that’s it for now.

It’s Just A Thought … Peace

Gaurang Sign

Leave a Reply

Your email address will not be published. Required fields are marked *