IIS redirect rule priority

Precedence is the same as the order they're specified in. IIS Manager has a "Move up" and "Move down" button that re-orders them for you.

For example:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
    <rules>
        <rule name="Rule1" stopProcessing="true">
            <match url="^foo/?bar=123"/>
            <action type="Rewrite" url="foo.aspx?bar=special" appendQueryString="false" />
        </rule>
        <rule name="Rule2" stopProcessing="true">
            <match url="^foo/?bar=([A-z0-9]+)"/>
            <action type="Rewrite" url="foo.aspx?bar={R:1}" appendQueryString="false" />
        </rule>
        <rule name="Rule3" stopProcessing="true">
            <match url="^foo/"/>
            <action type="Rewrite" url="somethingElse.aspx" appendQueryString="false" />
        </rule>
    </rules>
</rewrite>
</system.webServer>
</configuration>

Consider an incoming request for /foo?bar=123.

In this example, because Rule1 is first, it means that the request will be rewritten to foo.aspx?bar=special instead of foo.aspx?bar=123, even though it simultaneously matches Rule1, Rule2, and Rule3.

The stopProcessing="true" attribute ensures that other matching rules are not executed (i.e. Rule2 and Rule3).

Source: http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#Rules_Evaluation

Each configuration level in IIS can have zero or more rewrite rules defined. The rules are evaluated in the same order in which they are specified. The URL Rewrite Module processes the set of rules by using the following algorithm:

  1. First, the URL is matched against the pattern of a rule. If it does not match, the URL Rewrite Module immediately stops processing that rule, and goes on to the next rule.
  2. If a pattern matches and there are no conditions for the rule, the URL Rewrite Module performs the action specified for this rule and then goes on to the next rule, where it uses the substituted URL as an input for that rule.
  3. If a pattern matches and there are conditions for the rule, the URL Rewrite Module evaluates the conditions. If the evaluation is successful, the specified rule action is performed, and then the rewritten URL is used as input to the subsequent rule