簡體   English   中英

Azure web.config 永久重定向並獲取 307 狀態代碼而不是 301

[英]Azure web.config Permanent redirection and get 307 status code instead of 301

我正在嘗試將所有 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。

您在響應中指定 Strict_Transport_Security,這會激活HSTS

Chrome 甚至不調用服務器並直接通過 307 http 代碼重定向。 更多信息

根據您的 web.config,您指定了 redirectType="Permanent",它應該返回 301 狀態代碼。 您可以檢查是否也可以在其他瀏覽器中重現相同的行為。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM