web.config 中的 IIS 重写规则将 HTTPS 请求重定向到 HTTP [英] IIS Rewrite Rule in web.config to redirect HTTPS requests to HTTP

查看:27
本文介绍了web.config 中的 IIS 重写规则将 HTTPS 请求重定向到 HTTP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将所有 https 请求重定向到 http,例如,如果有人访问 https://www.example.com/another-page/http://www.example.com/另一页/

I need to redirect all https requests to http, for example, if someone visits https://www.example.com/another-page/ to http://www.example.com/another-page/

我现在在 web.config 中有以下重写规则,但它不能正常工作.它将 https://www.example.com/another-page/ 重定向到 https://www.example.com/,所以到网站的根目录,但我希望重定向保持不变在同一个 URL 中,并且只将 https 重写为 http.

I have the following rewrite rule in my web.config right now, but it's not working correctly. It's redirecting https://www.example.com/another-page/ to https://www.example.com/, so to the root of the site, but instead I want the redirect to stay in the same URL and only rewrite https to http.

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

任何有关更改上述规则的帮助,以便它仅将 https 更改为 http,但保留完整的 url 访问将不胜感激!

Any help on changing the above rule so that it only changes https to http, but keeps the full url visited would be greatly appreciated!

推荐答案

我设置了你的规则,稍微清理了一下,它奏效了;所以这并不是真正的答案.

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://stackoverflow.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://stackoverflow.com/a/9204355/292060

这篇关于web.config 中的 IIS 重写规则将 HTTPS 请求重定向到 HTTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆