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

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.