web.config 将非 www 重定向到 www,但有一个路由异常

web.config redirecting non www to www with one route exception

您好,我在使用重定向规则配置 web.config 文件时遇到问题。

我现在的重定向规则是

<rule name="Redirects to www.example.com" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
    <add input="{HTTP_HOST}" pattern="^example.com$" />

</conditions>
<action type="Redirect" url="https://www.example.com/{R:0}" />

现在我要排除urlhttps://example.com/some-url (and all url-s under this one) from the rule mentioned above. This rule should not redirect https://example.com/some-url to https://www.example.com/some-url.

那么如何从重定向规则中排除此 url。

你不能只添加这样的条件吗(注意:现在已编辑):

<add input="{REQUEST_URI}" pattern="/some-url/(.*)" negate="true" />

到条件列表?

编辑:并将条件设置为 "MatchAll" 而不是 "MatchAny"

未测试,但似乎可行?

(注意:作为第一条规则编辑的答案肯定是错误的;当前版本可能有效但仍未经测试)