1

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

4

2 回答 2

1

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

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

于 2019-03-04T20:13:02.360 回答
0

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

于 2019-02-28T09:51:52.633 回答