URL Rewrite Concepts

It's easy to get overwhelmed when you first start working with URL Rewrite; new rules can be difficult to create, especially when you use the Regular Expression (regex) syntax for them. However, once you understand some basic concepts, you will find that URL Rewrite is quite reasonable to learn, and soon you will be writing powerful rules with ease.

Before going further, we need to define the term “rule” as it pertains to URL Rewrite. For URL Rewrite, a rule is the main entity. For example, you can create a URL Rewrite rule to redirect your domain name from domain.com to www.domain.com. The whole set of conditions and actions is called a URL Rewrite rule. Here's an example of a fairly straightforward rule:

  <rule name="Redirect domain.com to www" patternSyntax="Wildcard">
    <match url="*" />
      <add input="{HTTP_HOST}" pattern="domain.com" />
    <action type="Redirect" url="http://www.domain.com/{R:0}" />

At a high level, URL Rewrite enables you to filter requests based on a condition and then take the appropriate action. Simply boiling URL Rewrite down to conditions and actions removes most barriers that many people have in understanding URL Rewrite.

However, that ten-thousand-foot overview misses a couple of other parts, but we'll cover them later and it will make more sense when the time comes. The other aspects of URL Rewrite rules include outbound rules, the ability to change the server headers on the way through, ...

Get Professional Microsoft IIS 8 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.