Using URL Rewrite Module 2.0

Introduction

This section of the documentation applies to the URL Rewrite Module Version 2.0 for IIS 7.

Microsoft URL Rewrite Module 2.0 for IIS 7 is an incremental release that includes all the features from version 1.1, and adds support for outbound response headers and content rewriting. More specifically, it can be used to:

  • Replace the URLs generated by a web application in the response HTML with a more user friendly and search engine friendly equivalent
  • Modify the links in the HTML markup generated by a web application behind a reverse proxy.
  • Fix up the content of any HTTP response by using regular expression pattern matching.
  • Modify HTTP request headers and IIS server variables.
  • Modify HTTP response headers

Features

URL Rewrite Module 2.0 includes the following key features:

  • Rules-based response rewriting engine. Outbound rules are used to express the logic of what to compare parts of the response with and what to do if comparison was successful. Web server and site administrators can use outbound rules to define complex response rewriting logic.
  • Rewriting within the content of specific HTML tags. Instead of scanning the entire response for a particular match, the rule can be configured to look only inside of certain HTML tags, such as <a>, <img>, etc. That way the pattern is greatly simplified and the process of applying the rule to the content is much faster comparing to applying the pattern to the entire response.
  • Pre-conditions for outbound rules. Applying rewrite rules on every response is an expensive operation and is not necessary in majority of the cases. Pre-conditions are used to check the response metadata to determine if outbound rules evaluation should be applied.
  • Rewriting of server variables and HTTP request headers. Various IIS server variables and HTTP request headers can be set by using rewrite rules.
  • Rewriting of HTTP response headers (new in RC). Outbound rewrite rules can be used modify any existing HTTP response headers or to set new ones.
  • Allow list for server variables (new in RC). To prevent distributed rewrite rules from accidentally or purposefully modifying IIS server variables that may affect security or runtime behavior of a web application the modifiable server variables now have to be explicitly added to the allow list.
  • HtmlEncode function (new in RC). Outbound rewrite may often use an un-trusted data (e.g. query string or HTTP headers) to build a replacement string to insert into the HTTP response. In those cases the HtmlEncode function should be used to prevent insertion of client-side scripts into the response, which could result in cross-site scripting vulnerability.
  • Tracking capture groups across rule conditions. The conditions back-referencing logic in URL Rewrite 1.1 worked only against the last matched conditions. In v2 it is possible to configure back-referencing logic to work against all matched conditions.
  • Logging of rewritten URLs (new in RC). The rewrite rules can be configured to log the rewritten URL in IIS W3C logs as opposed to logging an originally requested URL.
  • Updated user interface in IIS Manager (new in RC). The user interface has been significantly improved to better represent the module configuration and to simplify such common tasks as configuring of rewrite rules and rewrite conditions.

Installing the module

Download the URL Rewrite Module 2.0 by using the links at the module's home page at http://www.iis.net/extensions/urlrewrite

Note:

  • If a previous version of URL Rewrite Module, such as v1.0 and v1.1, is already installed then it will be upgraded to the v2.0 RC
  • If a beta version of the URL Rewrite Module 2.0 is already installed, then it has to be uninstalled before installing v2.0 RC.

Known Issues

  1. Response rewriting does not work with dynamic compression. You will have to disable IIS dynamic compression in order to use response rewriting.
  2. Outbound rules are not applied to chunked transfer encoded responses if rewriteBeforeCache is enabled. Set rewriteBeforeCache to false if you need to rewrite responses that are chunked transfer encoded.

Breaking changes

  1. {HTTP_CONTENT_TYPE} cannot be used anymore to access the response content type. Instead {RESPONSE_CONTENT_TYPE} is used. If any pre-conditions or conditions relied on {HTTP_CONTENT_TYPE} then they will stop working and will need to be modified to use {RESPONSE_CONTENT_TYPE}.
  2. It is not possible to set any server variable or a request HTTP header from a distributed rule unless that server variable or request header has been added to the <allowedServerVariables> collection. The restriction does not apply to global rules, which can set any server variable or request header without requiring them to be added to the <allowedServerVariables> collection.

Using the module

These articles cover the functionality of the URL Rewrite Module v2.0 and explain how to use it to accomplish common rewriting scenarios.

Walkthroughs

Functionality reference

Related Content

Comments

This is excellent!!

One of the "known issues" is that this doesn't work with dynamic compression. Is that a limitation that is addressable? I could really use the rewriter for my older ASP sites but would need dynamic compression too.

Thanks,

Phil Mattson

Aug 03 2009 by SQLRocks

Can you help me? I have been trying to use the web platform intstaller with the applications. I have the IIS 7 manager, and the web platform installer downloaded, but on home edition. I keep getting the message that home edition supports IIS 7.0 beta, but not IIS 7.0? If I download this (url version 2.0 IIS 7.0 beta) will that enable me to use the web installer, which I have downloaded but cannot apply the applications to. I have tried several things, and keep coming up at a dead end, can't get past the screen where web platform 2.0 has the web platform and media platform functions to start process of downloading applications. Thank you for any help, I'm sooooo confused at this point, staring at the screen isn't helping and about to give up and go back to notepad and write it out in xhtml by hand! I could have had it done already!
Mish181

Oct 25 2009 by mish181

Hello!
How to uninstall Module 1.1. I'm new user of IIS. Please help me!

Oct 28 2009 by ducduy dao

Sorry! It's completed!

Oct 28 2009 by ducduy dao

When is the release version planned? Would love to use this in a live environment, but can't while RC.

Dec 01 2009 by ovalsquare

Submit a Comment

You must Log In to comment.

Microsoft Communities