我正在尝试编写URL重写规则来强制HTTPS连接.除非请求使用localhost(例如http://localhost/mysite),否则应始终发生这种情况.
规则配置如下:
<rule name="Redirect to https" enabled="true" stopProcessing="true">
<match url="(.*)" negate="false" />
<conditions trackAllCaptures="false">
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{URL}" pattern="localhost" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
Run Code Online (Sandbox Code Playgroud)
我也尝试使用^ localhost和^ localhost /(.*)作为URL条件的模式,没有任何帮助.有没有人知道为什么这不起作用,这个问题的解决方案应该是什么?
我正在尝试使用 IIS 7.5 的 URL 重写模块将我的 ASP.NET 网站的所有 HTTP 请求重定向到 HTTPS。该网站目前运行良好,但强制用户在地址栏中输入 https://。
我按照本文中的说明进行操作。一切似乎都很好:我尝试将规则放入 web.config 中,它会按预期显示在 UI 中;我也做了相反的操作,当我使用 UI 添加规则时,可以看到 web.config 中的更改。我未选中该网站的 RequireSSL。不幸的是,当我尝试通过 http:// 访问该网站时,我仍然收到 404 错误。
我尝试了几种不同的操作网址,包括 {HTTP_HOST}/{R:1} 和下面显示的网址..没有任何效果。
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}"
redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
我对此还很陌生,目前非常沮丧。看来这应该容易很多。任何建议将不胜感激,谢谢..
从 ServerFault 重新发布,因为它已经有一段时间没有得到答复了。