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

Applying URL Rewrite Rules

URL Rewrite rules can be applied at different levels. Understanding these levels will help you know where to create the rules.

Rules are processed starting with the server level on down to the site and subfolders. URL Rewrite itself is processed very early in the IIS pipeline, before most IIS-related functionality. However, it runs after the site binding, so all page requests must be bound to a website, even if you use URL Rewrite. If the rule redirects back to the same server, you will need a binding for both URLs.

For global rules (<globalRules />), URL Rewrite runs during the PreBeginRequest event in the IIS pipeline, whereas for other rules (<rules />), URL Rewrite runs in the BeginRequest event in the IIS pipeline. The following shows the flow of the request as it pertains to URL Rewrite:

Incoming request ⇒ Site binding ⇒ If the request arrives using SSL, the packet is decrypted ⇒ URL Rewrite runs ⇒ Site is processed

Next, let's take a look at the different levels where rules can be applied.

Global Level—<globalRules>

Global rules apply to all traffic, regardless of the site, although you can apply conditions to rules so that they are filtered to just certain traffic.

Global rules are set in %windir%\System32\inetsrv\config\applicationHost.config in the following section:

<configuration>
 <system.webServer>
  <rewrite>
   <globalRules>
    <rule /> </globalRules> <outboundRules> <rule /> </outboundRules> </rewrite> </system.webServer> </configuration>  ...

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