gpt4 book ai didi

asp.net-mvc-3 - 如何使用 URL 重写规则过滤 URL

转载 作者:太空宇宙 更新时间:2023-11-03 14:14:51 25 4
gpt4 key购买 nike

<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" enabled="true" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTPS}" pattern="OFF" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
</rule>
</rules>
</rewrite>

我在我的 web.config 文件中使用了上面的 url 重写规则来为整个站点启用 SSL。现在我需要更改上面的规则来过滤 2 个应该作为 http 工作的 url。假设这些网址为 https://www.domain.com/owner/Marketinghttps://www.domain.com/owner/getinfo .目前这些网址是 https,因此高于规则。那么我如何更改上述规则以过滤 2 个以上的网址(即 http://www.domain.com/owner/Marketinghttp://www.domain.com/owner/getinfo )?

最佳答案

我会添加一个单独的规则来排除不应重定向到 https 的 url。

我现在无法测试它,因为我手边没有 IIS7。但试一试:

<rewrite>
<rules>
<rule name="Skip HTTPs" enabled="true" stopProcessing="true">
<match url="^(Marketing|getinfo)" ignoreCase="true" />
<conditions>
<add input="{HTTPS}" pattern="OFF" />
</conditions>
<action type="None" />
</rule>
<rule name="HTTP to HTTPS redirect" enabled="true" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTPS}" pattern="OFF" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
</rule>
</rules>
</rewrite>

请注意,您必须按照您的示例将该文件放入/owner/目录。

您可能已经看过相关文档 - 只需指出我在哪里找到它:

http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module

这里还有一个使用前瞻性正则表达式规则可能重复的问题:Rewriting URLs in IIS7

关于asp.net-mvc-3 - 如何使用 URL 重写规则过滤 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21983780/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com