简体   繁体   English

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

[英]IIS Rewrite Rule in web.config to redirect HTTPS requests to HTTP

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/ 我需要将所有https请求重定向到http,例如,如果有人访问https://www.example.com/another-page/访问http://www.example.com/another-page/

I have the following rewrite rule in my web.config right now, but it's not working correctly. 我现在在web.config中有以下重写规则,但它无法正常工作。 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. 它将https://www.example.com/another-page/重定向到https://www.example.com/ ,所以到了网站的根目录,但我希望重定向保留在同一个网址中将https重写为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>

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! 任何有关更改上述规则的帮助,以便它只将https更改为http,但保持访问的完整网址将非常感谢!

I set up your rule, cleaned up a little, and it worked; 我设定了你的规则,清理了一点,它起作用了; so this isn't really answering with much new. 所以这并没有真正回答新的问题。

Suggestion: Remove the onepage input condition just for testing, as cheesmacfly suggested in the question comment. 建议:删除仅用于测试的onepage输入条件,如cheesmacfly在问题评论中建议的那样。

Also, try changing the action to {R:1} instead of {R:0} . 另外,尝试将操作更改为{R:1}而不是{R:0} It shouldn't matter in this case, but I just like using 1 and up, to match the specific capturing group. 在这种情况下应该没关系,但我只是喜欢使用1和更高版本来匹配特定的捕获组。 R:0 means the entire matched string, which always confuses me just a little. R:0表示整个匹配的字符串,这总是让我感到困惑。

<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>

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. 当redirectType为Permanent,并且您仍在开发或测试时,浏览器通常会缓存先前的规则。 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 请参阅此答案中的第2和第3位: https//stackoverflow.com/a/9204355/292060

Please paste the below code in web.config file. 请将以下代码粘贴到web.config文件中。

<rule name="Redirect to http" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTP}" pattern="off" ignoreCase="true" />
    </conditions>
    <action type="Redirect" url="http://{HTTPS_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM