Microsoft URL Rewrite 101

Microsoft URL rewrite module is extremely easy to use not like Mod_rewrite!

Requirement: IIS 7

Features:

* Rules-based URL rewriting engine.
* Regular expression pattern matching.
* Wildcard pattern matching.
* Global and distributed rewrite rules.
* Access to server variables and HTTP headers.
* Rule templates.
* UI for testing of regular expression and wildcard patterns.
* UI for managing rewrite rules and rewrite maps.
* GUI tool for importing of mod_rewrite rules.
* and much more!

Once this module is installed there are three templates available when you add a new rule and they are:
# User-Friendly URL
# Rule with Rewrite Map
# Request Blocking

With these templates, it will make doing rewrite rule really simple! Plus the UI for testing and importing from mod_rewrite are extremely helpful.

Steps to add new rule:

# Go to IIS Manager
# Select “Default Web Site”
# In the Feature View click “URL Rewrite“
# In the “Actions” pane on right-hand side click on “Add rules…”
# In the "Add Rules" dialog, select the "user-friendly URL" and click "Ok"

That's it!

Create a test page:

Copy the following ASP.NET code and put it in the %SystemDrive%\inetpub\wwwroot\ folder in a file called article.aspx:


<%@ Page Language="C#" %>

URL Rewrite Module Test

URL Rewrite Module Test Page

Server Variable
Value

Original URL:
<%= Request.ServerVariables["HTTP_X_ORIGINAL_URL"] %>

Final URL:
<%= Request.ServerVariables["SCRIPT_NAME"] + "?" + Request.ServerVariables["QUERY_STRING"] %>

Testing the rule

To test that the rule redirects requests correctly, open a Web browser and request the following URL:

http://localhost/article/342/some-article-title
will be rewritten as:
http://localhost/article.aspx?id=342&title=some-article-title.

There are so much more you can do with it!

You can download it here: http://www.iis.net/downloads/default.aspx?tabid=34&g=6&i=1691

You can get more information here: http://learn.iis.net/page.aspx/734/url-rewrite-module/

Forums: