我已经在我的 IIS 服务器上安装了 WordPress,并且还安装了 SSL 证书。
我已经研究了我能找到的每一个线程,但仍然无法正常工作。我找到了 this thread来自 Apache 的一个人,他面临同样的问题,但我在 IIS 上,不知道如何让它与 IIS 一起工作。
与该线程类似,这是正在发生的事情:
https://www.example.com
运行良好
https://example.com
正在重定向到上面,也很棒!
问题是:
http://www.example.com
仍然可以访问,不好,因为这应该重定向到 https://www.example.com
还有:
http://example.com
重定向到 http://www.example.com
。
我该如何解决这个问题,以便它全部重定向到 https://www.example.com
?
我在 IIS 上,这是我的 web.config
的样子:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="WordPress Rule" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
最佳答案
感谢 Dan,这成功了。
<?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>
<rule name="WordPress Rule" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
关于wordpress - 使用 web.config 将 HTTP 重定向到 HTTPs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37099164/