web.config 301 重定向,Windows 托管



我正在努力让 web.config 文件用于重定向 - 我是第一次这样做。我一直在尝试在这个网站和其他地方找到的许多不同的代码。 我们有HTTPS网站,我需要将HTTP url-s重定向到HTTPS。 该网站是用HTML编写的,我们有Windows托管。

我设置了一个 web.config 文件并添加了下面的代码。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

我在这里错过了什么吗? 还是需要一些时间才能生效?

提前非常感谢!

卡德里

从Scott Hanselman几年前的博客中,你应该试试这个:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

最新更新