【发布时间】:2017-06-07 20:48:23
【问题描述】:
我正在尝试配置 Umbraco,以便所有到后台 (www.mydomain.com/umbraco) 的请求都被重定向到 https,所有非后台请求都被转发到 http。
我可以通过设置这个 web config appsetting 密钥轻松让后台使用 SSL:
<add key="umbracoUseSSL" value="false" />
但是,我正在努力让所有其他页面强制使用 http。该证书是自签名的,因此我不希望最终用户收到 SSL 错误。我在 web.config 中尝试过这个重写规则,但没有影响。
<rule name="No-https" enabled="true" stopProcessing="true">
<match url=".*" negate="false" />
<conditions>
<add input="{HTTPS}" pattern="on" />
<add input="{URL}" pattern="umbraco" negate="true" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}{REQUEST_URI}" />
</rule>
我的目标是将任何对 https://www.mydomain.com 的请求重定向到 http://www.mydomain.com,除非它与文件夹匹配/umbraco。
如果我有这个规则,所有的http请求都会重定向到https:
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
但是当我否定规则时,它不再有任何作用?
<rule name="Redirect to HTTP" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" negate="true" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
更新。看起来无法处理重定向,因为浏览器在重写规则运行之前给出了 https 错误? Redirect from https to http when the SSL cert is no longer valid。使用自签名证书时有什么方法可以重定向到 http 吗?
【问题讨论】:
-
在用户看到证书警告之前,无法从 HTTPS 重定向到 HTTP。这在您发布的 SO 链接中进行了说明。
标签: asp.net iis url-rewriting web-config umbraco