O'Reilly logo

Professional Microsoft IIS 8 by Benjamin Perkins, Dennis Glendenning, Scott Forsyth, Jeff Cochran, Kenneth Schaefer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

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

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required