【问题标题】:HTTPS redirect in web.config leads to ERR_TOO_MANY_REDIRECTSweb.config 中的 HTTPS 重定向导致 ERR_TOO_MANY_REDIRECTS
【发布时间】:2017-10-01 11:45:26
【问题描述】:

我正在尝试在 web.config 中添加重定向规则,以仅以 HTTPS 提供我的网页,而根本不提供 HTTP;到目前为止,我已经使用了这个规则集(连同我的 404 重定向):

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
       <rewrite>
            <rules>
                <clear />
                <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="Permanent" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>
        <directoryBrowse enabled="false" />
        <httpErrors errorMode="Custom" existingResponse="Auto">
            <remove statusCode="404" subStatusCode="-1" />
            <error statusCode="404" subStatusCode="-1" prefixLanguageFilePath="" path="index.php" responseMode="Redirect" />
        </httpErrors>
    </system.webServer>
</configuration>

但是,这会导致 ERR_TOO_MANY_REDIRECTS;这个 web.config 有什么问题导致这个?它似乎适用于其他用户。

我已经尝试过这些帖子中的建议; Redirect loop when forcing HTTPS、URL Rewrite causing redirect loop、this blog 和 this blog。

【问题讨论】:

    标签: redirect https web-config


    【解决方案1】:

    也许我来的有点晚,但是下面的 Rewrite 规则有助于解决重定向错误:

    <rule name="Redirect to https" stopProcessing="true">
      <match url="(.*)" />
      <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="^example\.com$" />
        <add input="{SERVER_PORT}" pattern="^80$" />
      </conditions>
      <action type="Redirect" url="https://www.example.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
    </rule>
    

    【讨论】:

      猜你喜欢
      • 2016-06-15
      • 2020-11-09
      • 1970-01-01
      • 2013-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-13
      相关资源
      最近更新 更多