0

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

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

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

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

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

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

4

1 回答 1

0

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

<unless header="HTTP_HOST" match="localhost">
  <if header="HTTPS" match="^OFF$">
    <redirect url="(.*)" to="https://sub.mydomain.com$1" />
  </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


于 2016-08-15T13:59:04.810 回答