目前只有一页和所有依赖项(css、jpg 等)是 SSL。我创建了以下重写:
<rule name="Not Appointment Form 4.1 SSL" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" negate="false" />
<conditions>
<!-- check if https is on -->
<add input="{HTTPS}" pattern="on" />
<!-- I'm only interested in the aspx files -->
<add input="{PATH_TRANSLATED}" pattern=".aspx$" />
<!-- anything BUT the page to be secured -->
<add input="{PATH_INFO}" pattern="page-to-be-secured.aspx" negate="true" />
</conditions>
<action type="Redirect" url="http://mydomain{PATH_INFO}" redirectType="Permanent" />
</rule>
我试过将页面名称放在匹配 url (negate="false") 中,但仍然不起作用。
我已经测试了每个单独的条件,它们都单独工作,但作为一个整体,它没有重定向到非 HTTPS 页面。
最佳答案
一个简单的方法是:
<rule name="Not Appointment Form 4.1 SSL" stopProcessing="true">
<match url="^(.*)\.aspx$" />
<conditions>
<add input="{R:1}" pattern="page-to-be-secured" negate="true" />
<add input="{HTTPS}" pattern="^ON$" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/{R:0}" />
</rule>
该规则适用于每个以
.aspx
结尾的请求 url。如果对应于 {R:1}
之前的部分的第一个反向引用 ( .aspx
) 与 page-to-be-secured
不匹配并且正在使用 HTTPS
,则触发重定向。关于regex - Url Rewrite HTTPS -> HTTP 除了某些页面(IIS 7),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16566744/