Search code examples
web-configwindows-server-2016

How do I exclude a directory from a web.config rewrite rule?


We have a rewrite rule to http to https, and that works fine. However, we have one directory "complaints" that we do not want the rule applied to. I thought I knew how to do this, and have researched it for the past couple hours and it seems correct, but it doesn't work.

This is the rule...

<rule name="https redirect" stopProcessing="true">
     <match url="(.*)" />
     <conditions>
          <add input="{HTTPS}" pattern="^OFF$" />
          <add input="{REQUEST_URI}" pattern="^complaints$" negate="true"/>
     </conditions>
     <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" />
</rule>

I have also tried it this way, which also does not work for me...

<rules>
<rule name="skip rule" stopProcessing="true">
    <match url="^complaints$" />
    <action type="None" />
</rule>
<rule name="https redirect" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTPS}" pattern="^OFF$" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" />
</rule>

I have also run IISRESET after making these changes.

Anyone know why this is not ignoring the "complaints" directory?


Solution

  • I removed the extra code from the web.config file that was working, and instead just created a web.config in the "complaints" directory with the following...

    <rules>
         <clear />
    </rules>
    

    This causes the "complaints" directory to ignore the rule inherited from the parent directory.