【问题标题】:Intelligencia.UrlRewriter check domain to redirect to httpsIntelligencia.UrlRewriter 检查域以重定向到 https
【发布时间】:2016-08-15 08:28:34
【问题描述】:

我在排除 locahost 时尝试在我的网站上强制使用 https 时遇到问题 我目前正在使用 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 连接?

【问题讨论】:

  • 您想用mydomain 匹配除 URL 之外的任何内容吗?试试url="^(?!.*mydomain)(.*)"
  • 我正在尝试排除本地主机。我已经编辑了问题以使其更清楚。

标签: asp.net regex url urlrewriter.net


【解决方案1】:

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

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

通过添加&lt;unless header="HTTP_HOST" match="localhost"&gt; 标签,我可以排除某些主机,但仍允许将其他主机重定向到https。换句话说:

这将是强制的:


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

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

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


但这将不会改变

http://localhost/default.html


【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-25
    • 1970-01-01
    • 2019-11-15
    • 1970-01-01
    • 2018-04-27
    • 1970-01-01
    • 2013-06-29
    • 2018-06-02
    相关资源
    最近更新 更多