What Is URL Rewrite Module & How to Use It in IIS?

What Is URL Rewrite Module & How to Use It in IIS?

The walkthrough will teach you how to use the popular URL Rewrite Module to create and even test the rewrite rules within IIS (Internet Information Services) 7.0. Note that, it is also possible to take advantage of Apache’s mod_rewrite module to implement URL rewriting, which is however beyond the scope of this tutorial. As is shown, we are about to give the exact definition of the IIS URL Rewrite Module at the start.

What Is Exactly the URL Rewrite Module?

Simply speaking, the URL Rewrite Module for IIS 7 is such a useful tool that empowers web administrators to create serial rules to obtain those URLs that are friendly enough for readers search engine bots. In the further, you can also make good use of this Microsoft URL Rewrite Module to carry out the following URL manipulation tasks:

  • Rewrite URLs on the basis of IIS server variables and HTTP headers.
  • Apply powerful rewriting rules to convert complex URLs into concise and consistent web addresses.
  • Control the access to your website content according to correspondent request metadata or URL segments.
  • Reshape your web application (like WebMatrix web publishing tool) URLs in order to generate SEF (search engine friendly) results.
  • Send out custom responses, forbid bad HTTP requests and create redirects corresponding to the logic specified in your rewrite rules.

The newest version of URL Rewrite Module is 2.0, and you can download it for the stand-alone IIS server via this page. Pay attention that, the Microsoft extension is always pre-installed on any websites hosted on WAWS (Windows Azure Web Sites). In the following parts, we’d like to demonstrate how to perform common URL rewriting scenarios using the mentioned URL rewrite module 2.0.

About the URL Rewrite Module

Important to Note: If you already have a previous version of the URL rewrite module like v1.1 locally, then you will need to upgrade it to the 2.0 version. For the RC version of your URL rewrite module, it also needs to be updated to the RTW version.

Preparatory Work before Starting Out

By default the IIS is not enabled in the Windows 7 installation, hence you are expected to manually enable the IIS7 for future site configuration. To do so, just locate and open the “Start” menu of your personal computer. Upon entering the “Control Panel” interface, click on the “Programs and Features” link and you will be able to find this “Turn Windows features on or off” option out there.

Turn on Windows Features

Within this pop-up options menu, there are plenty of Windows functionalities, be activated and unactivated. To turn on/off a feature, simply check/uncheck its box. In the next screencast, you are required to select some needed functions within the two “Internet Information Services” and “World Wide Web Services” folders. Beware that, a filled box means that only some of the included Windows features are switched on. Do remember to click on the bottom “OK” button to take effect.

Choose Your Windows Features

How to Get Started with the IIS URL Rewrite Module?

Now that the IIS7 has been initialized on your computer, it’s time to install the newly-downloaded URL Rewrite Module 2.0. To do this, you shall run your installer package using administrator role. This requires you to log onto the server with your actual account that is named as “Administrator”. Also, it is possible to use one account with enough administrator privileges to run as administrator. Here, just make a hit on this “Run” button.

Run Windows Installer Package

And next, you will be prompted to agree to the “License Agreement.” It might take a while to accomplish this installation task, and all you need to do is click on the final “Finish” button to end the entire process.

Perform Installation Task

How to Create Rewriting Rules in the IIS7 Management Console?

Assuming that you’ve successfully installed the URL rewrite module, we will focus on its basic implementation, namely creating rewrite rules for your website. Before making any configurations, you should firstly start IIS manager on the administrative services console. This only requires you to type in “inetmgr” within the “Search Programs and Files” box located at the “Start” menu.

Start Your IIS Manager

Select Out URL Rewrite Option
Once clicked on this program, a new dialog box will appear onscreen. Just search and click on this “URL Rewrite” icon right under the “IIS” area. In the meanwhile, choose to “Open” Features inside the right-hand “Actions” section.

Select Out URL Rewrite

Add Rules for Modules
As you may notice, there are two different views on the IIS management console, including “Feature View” and “Content View.” To continue, just make a click on the “Add Rule(s)” option from the left “Actions” section within the former “Feature View”.

Add Rules for Module

Next, choose the “Blank Rule” under the “Inbound Rules” and then press the “OK” button.

Click on Blank Rules

Name Your Rewrite Name
To edit your inbound rule, you will firstly input a name that can identify your rule in the text box, such as “Rewrite to article.aspx”. Just leave the “Match URL” options to the defaults.

Create Rule Name & Pattern

Important to Note: To test whether the future rewrite rules can work as expected, you would create an ASP.NET page that can identify your web server variables and then output specified values in any web browser. Refer to the following configuration code introduced from the official IIS.net page.

Your ASP.NET Configuration Code

Create a Rewrite Pattern
Within this “Pattern” box, you can enter a short line of string as below. Beware that, this example string is also instanced from the IIS.net official page, and it helps define the rewrite patterns that begin with the “/article/” characters and include many additional characters after the “article/”. Pay attention that, the bracketed expressions can also be re-configured later on.


Define Your Rewrite Type
Below is the “Action” section, and you are supposed to select out the “Rewrite” option from the “Action Type” drop-down list. After that, you also need to fill in the “Rewrite URL” text box using the below string. Note also that this official string would re-define the inbound URLs, and the {R:2} and {R:1} values are actually the back-references to the bracketed expressions above.


Rewrite Pattern & Type

Once done with all those settings above, just leave the rest options to the default values and make a click on the right-side “Apply” option to store changes.

Put Your Rewrite Rules into the Test
In most instances, the newly-created rewrite rules will be available in the Web.config. Given that you’re using the WebSitePanel control panel, you can view and edit the definition of rewrite rules by entering this “Web.config” file located at the “wwwroot” folder. If you are satisfied with rule configurations, you can type in the testing URL in any web browser to check whether the rule redirects are in working order.

Find Your Web.config File