Disable IIS7 URL Rewrite inheritance on a per site basis?
I have many global IIS7 URL Rewrite rules and they by default apply to all sites. Well there are several sites that i would like to disable this rewrite inheritance on for all rules. How can I do this? I tried the following without joy:
开发者_JAVA技巧 <rewrite>
<rules>
<clear />
</rules>
</rewrite>
Sorry, that cannot be done:
Global rewrite rules are used to define server-wide URL rewriting logic. These rules are defined within applicationHost.config file and they cannot be overridden or disabled on any lower configuration levels, such as site or virtual directory. Global rules always operate on the absolute URL path (that is, requested URI without the server name).
and
Global rule set is always evaluated first, and after that distributed rule set will be evaluated by using a URL string produced by global rule set.
http://learn.iis.net/page.aspx/468/using-global-and-distributed-rewrite-rules/
If you are able to move the functionality you need out of the global rules and into the web.config for your sites, you can add a condition on each rule to either opt-in or opt-out of each rule based on the presence of a local file for that site. This would allow you to deploy a common set of code and config, but with local/per-site customization.
Example of an opt-in rule:
<rule name="HTTP to HTTPS Redirect" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTPS}" pattern="off" />
<!-- Opt-in to rule via presense of a local file -->
<add input="{DOCUMENT_ROOT}/Local/rewrite-rule-enable-https.txt" matchType="IsFile" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
Note: The Local folder is not deployed, but rather used to store per-site files.
So essentially this rule does not turn on unless a file called "rewrite-rule-enable-https.txt" is found in the /Local folder on site.
精彩评论