IIS 8.5 disable rewrite rule for virtual directory

2019-09-04 06:49发布

I have a rewrite rule for my "Default Web Site" (aka at my wwwroot's web.config) to redirect all HTTP request to HTTPS as follows:

<rule name="http to https" enabled="true" stopProcessing="true">
  <match url="(.*)" />
  <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
    <add input="{HTTPS}" pattern="^OFF$" />
  </conditions>
  <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
</rule>

Now I want to disable or exclude a Virtual Directory under this so I can reach that only with HTTP. How to do this?

What I have tried: Creating a rule that matches the virt.dir's name, and chose to stop any further action (no success):

<rule name="testsite no https" enabled="true" stopProcessing="true">
  <match url="(testsite)" ignoreCase="true" />
  <action type="None" />
  <conditions>
    <add input="{URL}" pattern="(testsite)" />
  </conditions>
</rule>

Added a negate condition for the first rule (no success)

 <add input="{URL}" pattern="(testsite)" negate="true" />

What am I doing wrong?

1条回答
时光不老,我们不散
2楼-- · 2019-09-04 07:10

You do not need a separate rule for that.

  1. Open IIS manager expand the site and select the virtual directory.
  2. In the center pane you can see all the modules. Double click URL Rewrite.
  3. Select the redirect rule and in the actions pane click disable rule.

Also you can add a web.config in your virtual directory and do below

<system.webServer>
    <rewrite>
      <rules>
        <remove name="testsite no https" />
      </rules>
    </rewrite>
</system.webServer>

Or

Change your match condition from <match url="(.*)" /> to <match url="^((?!testsite).)*$" /> so basically this will work for all URLS except the one containing testsite.

Hope this helps.

查看更多
登录 后发表回答