且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

IIS重写Web.config中的规则以将HTTPS请求重定向到HTTP

更新时间:2021-06-28 09:43:18

我设置了你的规则,清理了一点,它工作了;所以这并没有真正回答新的问题。

I set up your rule, cleaned up a little, and it worked; so this isn't really answering with much new.

建议:删除 onepage 输入条件仅用于测试,正如cheesmacfly在问题评论中建议的那样。

Suggestion: Remove the onepage input condition just for testing, as cheesmacfly suggested in the question comment.

另外,尝试将操作更改为 {R:1} 而不是 {R:0} 。在这种情况下应该没关系,但我只是喜欢使用1和更高版本来匹配特定的捕获组。 R:0表示整个匹配的字符串,这总是让我感到困惑。

Also, try changing the action to {R:1} instead of {R:0}. It shouldn't matter in this case, but I just like using 1 and up, to match the specific capturing group. R:0 means the entire matched string, which always confuses me just a little.

<rule name="Redirect to HTTP" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTPS}" pattern="^ON$" />
    </conditions>
    <action type="Redirect" url="http://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>

一种可能是您的浏览器缓存了之前的规则尝试。当redirectType为Permanent,并且您仍在开发或测试时,浏览器通常会缓存先前的规则。清除浏览器缓存,和/或删除永久,和/或以隐身模式浏览。完成测试后,将其更改为永久性。请参阅此答案中的第2和第3位: https://***.com/a/9204355/292060

One possibility is that your browser has cached a previous attempt of your rules. When the redirectType is Permanent, and you're still developing or testing, the browser often caches a previous rule. Clear your browser cache, and/or remove the Permanent, and/or browse in incognito mode. When done testing, change it to permanent. See number 2 and 3 in this answer: https://***.com/a/9204355/292060