Intelligencia.UrlRewriter 检查域以重定向到 https

Intelligencia.UrlRewriter check domain to redirect to https

我在尝试在我的网站上强制使用 https 时遇到问题,同时 排除 locahost 我目前正在使用 Intelligencia.UrlRewriter 重写任何 url,并且设置了以下规则:

<if header="HTTPS" match="^OFF$">
<redirect url="(.*)" to="https://sub.mydomain.com" />
</if>

这重定向很好,但我想确保我的本地主机调试不受影响。这显然在不同的 URL 下运行。所以我尝试了:

<if header="HTTPS" match="^OFF$">
<redirect url="(.*)mydomain" to="https://sub.mydomain.com" />
</if>

然而,这不起作用。我相信这样做的原因可能是它 仅评估 .com. 之后的任何内容 我曾尝试搜索文档,但没有成功。

除了我的本地主机之外,我如何始终强制使用 https 连接?

我设法找到了解决问题的办法:

<unless header="HTTP_HOST" match="localhost">
  <if header="HTTPS" match="^OFF$">
    <redirect url="(.*)" to="https://sub.mydomain.com" />
  </if>
</unless>

通过添加 <unless header="HTTP_HOST" match="localhost"> 标签,我可以排除某些主机并仍然允许其他主机重定向到 https。换句话说:

这将被强制:


http://sub.mydomain.com/default.html

收件人(注意 https 中的 s):

https://sub.mydomain.com/defualt.html


但这不会改变:

http://localhost/default.html