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

时间:2019-02-27 19:58:20

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

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

更新

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

如果我搜索:

domaine.com重定向为301

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

www.domaine.com重定向为307

更新

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

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

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