locked
What determines the order of the execution of the rules RRS feed

  • Question

  • User-1142219764 posted

    The application has the following Rewrite rules

    <rules>
    <rule name="no path" stopProcessing="true">
    <match url="(.*)"/>
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
    <add input="{URL}" pattern="^(/)?$"/>
    </conditions>
    <action type="Redirect" url="https://www.example.se/privat/"/>
    </rule>

    <rule name="missing trailing /privat" stopProcessing="true">
    <match url="(.*)"/>
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
    <add input="{REQUEST_URI}" pattern="^/privat$"/>
    </conditions>
    <action type="Redirect" url="https://www.example.se/privat/"/>
    </rule>

    <rule name="missing www" stopProcessing="true">
    <match url="(.*)"/>
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
    <add input="{HTTP_HOST}" pattern="^example.se$"/>
    </conditions>
    <action type="Redirect" url="https://www.example.se{REQUEST_URI}"/>
    </rule>

    <rule name="not https" stopProcessing="true">
    <match url="(.*)"/>
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
    <add input="{HTTPS}" pattern="^OFF$" />
    </conditions>
    <action type="Redirect" url="https://www.example.se{REQUEST_URI}"/>
    </rule>
    </rules>

    However the order of the rules does not have any http to http redirect, still the following order is observed


    301 http://example.se/ 
    301 http://www.example.se/ 
    200 https://www.example.se/privat/

    Can anybody assist what determines the order of rules

    Wednesday, February 12, 2020 3:03 PM

All replies

  • User-2064283741 posted

    The best way to follow this is to follow failed request tracing

    https://forums.iis.net/t/1193146.aspx?Rule+not+working+as+expected+Use+Failed+Request+Tracing

    That is if it hitting your server at all for the first first request. (301 are often cached on the client for a long time or it could be another provider in the way where you have a redirect)

    If it is hitting your server also look at server level rewrite rules

    Wednesday, February 12, 2020 3:20 PM
  • User-460007017 posted

    Hi amol.mahui,

    IIS URL rewrite module will match the rule one by one from top to the bottom. If the request trigger one rule, IIS return301.  The redirected 301 rule also need to pass through the rewrite rule process again. Until all rules don't match your request url.

    Your redirection works fine on my side. "no path" redirect the URL directly.

    If I modify the order like:

    Then the redirection would looks like your description

    Since you are using 301 redirection, please try to clean your browser cache and recycle applicationpool.

    Anyway, FRT log will tell us why url get redirected and you can view the order list.

    https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/using-failed-request-tracing-to-trace-rewrite-rules

    If the reply is helpful, it is appreciated if you could mark it as answer.

    Best Regards,

    Jokies Ding

    Thursday, February 13, 2020 9:34 AM