我正在尝试从表单中重写网址:
https://example.com/about
到表格
http://example.com/about
<!-- http:// to https:// rule -->
<rule name="ForceHttpsBilling" stopProcessing="true">
<match url="(.*)billing/(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="false" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}{REQUEST_URI}" />
</rule>
<!-- https:// to http:// rule -->
<rule name="ForceNonHttps" stopProcessing="true">
<match url="(.*)billing/(.*)" ignoreCase="true" negate="true" />
<conditions>
<add input="{SERVER_PORT}" pattern="^443$" />
</conditions>
<action type="Redirect" redirectType="Found" url="http://{HTTP_HOST}{REQUEST_URI}" />
</rule>
我不知所措;我一直在浏览网页上的例子,并尝试我能想到的每一种语法。对于任何https请求,我指定的重写规则似乎根本不起作用 ,好像所有 https://
请求对重写引擎都是不可见的。
规则运作良好;见下面的答案。
答案 0 :(得分:26)
原来我有端口:443绑定到不同的网站!
上述重写规则适用于http://到https://重写,反之亦然 - 尽管可能有更优化或简单的方法来执行此操作。
留下这个问题,以便将来的航海者找到,因为我没有在网上看到很多关于https://到http://重写场景的好例子。
答案 1 :(得分:5)
这篇文章有点旧,但我想回答。我正在使用ASP.Net MVC3,上面的Fabio的答案对我不起作用。我提出的最简单的解决方案是处理https重定向到http,同时仍然允许有效的https页面请求安全内容只是在我的https / http重定向上面添加白名单规则:
<rule name="WhiteList - content folder" stopProcessing="true">
<match url="^content/"/>
<conditions logicalGrouping="MatchAll" trackAllCaptures="false"/>
<action type="None"/>
</rule>
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)billing/(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/billing/" redirectType="SeeOther" />
</rule>
<rule name="ForceNonHttps" stopProcessing="true">
<match url="(.*)billing/(.*)" ignoreCase="true" negate="true" />
<conditions>
<add input="{SERVER_PORT}" pattern="^443$" />
</conditions>
<action type="Redirect" redirectType="Found" url="http://{HTTP_HOST}{REQUEST_URI}" />
</rule>
答案 2 :(得分:2)
您的解决方案有效,但问题是:您的第二条指令终止任何链接的第一条指令不是(。)billing /(.),包括您的css,js和图像。
您可以将此https用于http规则:
<rule name="HTTPS to HTTP redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{RequiresSSL:{R:1}}" pattern="(.+)" negate="true" />
<add input="{HTTPS}" pattern="on" ignoreCase="true" />
<add input="{REQUEST_URI}" pattern="^(.+)\.(?!aspx)" negate="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="http://{HTTP_HOST}/{R:1}" />
</rule>
答案 3 :(得分:1)
请首先考虑绑定 https到您的网站,以使下面的重定向模块工作至关重要(因此请将您的网络应用绑定到自签名或有效证书)
web.config中的最后一部分,用于将 https 重定向到 http :
<rewrite>
<rules>
<rule name="Force NonHTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="on" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/{REQUEST_URI}" />
</rule>
</rules>
</rewrite>
如果在重写模块中需要等效的IIS GUI,请参见下图
来源:查看tech-net以获取更多详细信息和分步指南。