Azure web.config永久重定向并获取307状态代码而不是301

问题描述 投票:1回答:2

我正在尝试将所有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>

enter image description here

UPDATE

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

如果我搜索:

domaine.com重定向是301

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

www.domaine.com重定向是307

UPDATE

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

redirect web-config azure-web-sites http-status-code-301 http-status-code-307
2个回答
1
投票

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

Chrome甚至不会调用服务器并直接通过307 http代码重定向。 More info


0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.