首页 > 解决方案 > 无法清除子文件夹中的重写规则

问题描述

我在网站根目录的 web.config 中有这个规则,它重定向到 HTTPS:

<rewrite>
<rules>
<rule name="HTTPS" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
    <match url="*" negate="false" />
    <conditions logicalGrouping="MatchAny">
        <add input="{HTTPS}" pattern="off" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>

在一个子文件夹中,我有单独的配置文件,我想清除重定向到 HTTPS,但这个文件夹也重定向到 HTTPS:

    <rewrite>
        <rules>
            <clear />
        </rules>
    </rewrite>

标签: url-rewritingweb-configiis-8

解决方案


你不能这样做。规则只能存储在 web.config 中定义。您可以将它们放在那里或提供存储规则的文件的路径(但它仍然在 web.config 中定义),如下所示:

<system.webServer>
    <rewrite>
        <rules configSource="App_Config\RewriteRules.config" />
        <outboundRules configSource="App_Config\OutboundRewriteRules.config" />
        <rewriteMaps configSource="App_Config\RewriteMaps.config" />
    </rewrite>
</system.webServer>

如果您希望某些 URL 不被重定向到 HTTPS,那么您需要创建一个智能规则来检测这一点(或具有一组规则)。


推荐阅读