【问题标题】:Use web.config to redirect HTTP to HTTPs使用 web.config 将 HTTP 重定向到 HTTPS
【发布时间】:2016-09-03 02:35:44
【问题描述】:

我已经在我的 IIS 服务器上安装了 WordPress,并且还安装了 SSL 证书。

我已经研究了我能找到的每一个线程,但仍然无法让它工作。我从 Apache 上遇到同样问题的一个人那里找到了this thread,但我在 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>

【问题讨论】:

  • 你试过this吗?
  • 除了已经存在的规则之外,我还会添加该规则吗?如果是,新规则是在之前还是之后?
  • 上次我尝试过,我网站上的所有图片都坏了,我还是继续了,它成功了。谢谢:)

标签: wordpress redirect ssl iis


【解决方案1】:

感谢 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>

【讨论】:

    【解决方案2】:

    首先,我建议您在 IIS 上获取名为“URL Rewrite”的扩展名。

    那么您应该将您的代码与以下代码匹配:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <system.webServer>
        <rewrite>
          <rules>
            <rule name="HTTP/S to HTTPS Redirect" enabled="true" stopProcessing="true">
            <match url="(.*)" />
            <conditions logicalGrouping="MatchAny">
              <add input="{SERVER_PORT_SECURE}" pattern="^1$" />
              <add input="{SERVER_PORT_SECURE}" pattern="^0$" />
            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}/OWA/" redirectType="Permanent" />
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
    </configuration>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-13
      • 1970-01-01
      • 1970-01-01
      • 2017-12-01
      • 2019-03-18
      • 2016-03-27
      • 2012-10-11
      相关资源
      最近更新 更多