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)
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
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.
And that’s it !! Now if you try to browse to that same page, it will show URL as http://localhost/test
Pretty cool huh ?
Well that’s it for now.
It’s Just A Thought …