【问题标题】:Azure web.config Permanent redirection and get 307 status code instead of 301Azure web.config 永久重定向并获得 307 状态码而不是 301
【发布时间】:2019-07-21 15:38:02
【问题描述】:

我正在尝试将所有 http 流量重定向到 https,同时返回 301 状态代码。出于某种原因,我得到了 307 状态,但我不知道为什么。我试图搜索我是否遗漏了配置中的某些内容,但它似乎与我看到的所有内容相似。

我的 web.config

    <rewrite>
      <rules>
        <rule name="ForceWWW" stopProcessing="true">
          <match url=".*" ignoreCase="true" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^MY_DOMAINE" />
          </conditions>
          <action type="Redirect" url="https://www.MY_DOMAINE/{R:0}" redirectType="Permanent" />
        </rule>
        <rule name="HTTP to HTTPS redirect" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
        </rule>
      </rules>
      <outboundRules>
        <rule name="Add Strict-Transport-Security when HTTPS" enabled="true">
          <match serverVariable="RESPONSE_Strict_Transport_Security" pattern=".*" />
          <conditions>
            <add input="{HTTPS}" pattern="on" ignoreCase="true" />
          </conditions>
          <action type="Rewrite" value="max-age=31536000" />
        </rule>
      </outboundRules>
    </rewrite>

更新

我刚刚发现了一些有趣的东西。例如我的域名是 domaine.com

如果我搜索:

domaine.com 重定向为 301

http://www.domaine.com重定向是307

www.domaine.com 重定向为 307

更新

我只遇到了 Chrome 的问题。其他浏览器有重定向的 301 状态。

【问题讨论】:

    标签: redirect web-config azure-web-app-service http-status-code-301 http-status-code-307


    【解决方案1】:

    您在响应中指定 Strict_Transport_Security,这会激活 HSTS

    Chrome 甚至不调用服务器,而是直接通过 307 http 代码进行重定向。 More info

    【讨论】:

      【解决方案2】:

      根据您的 web.config,您指定了 redirectType="Permanent",它应该返回 301 状态代码。 您可以检查相同的行为是否也可以在其他浏览器中重现。

      【讨论】:

      • 我刚刚在其他浏览器中尝试过,我得到了 301 状态。 Chrome 有什么特别之处吗??
      • 我不太确定 chrome 的行为。您可以查看-stackoverflow.com/questions/27945501/…
      猜你喜欢
      • 1970-01-01
      • 2011-11-13
      • 1970-01-01
      • 2018-11-04
      • 2014-09-24
      • 2013-07-17
      • 1970-01-01
      • 1970-01-01
      • 2012-05-31
      相关资源
      最近更新 更多