问题
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:
You do not need a separate rule for that.
- Open IIS manager expand the site and select the virtual directory.
- In the center pane you can see all the modules. Double click URL Rewrite.
- 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.
来源:https://stackoverflow.com/questions/39445929/iis-8-5-disable-rewrite-rule-for-virtual-directory