?
This document uses PHP Chinese website manual Release
Location
響應(yīng)頭指示URL的頁面重定向到。它僅在提供3xx
狀態(tài)響應(yīng)時才提供意義。
用于使新請求獲取指向的頁面的 HTTP 方法Location
取決于原始方法和重定向類型:
如果303
(另請參見)響應(yīng)始終導(dǎo)致使用GET
方法,307
(臨時重定向)和308
(永久重定向)不會更改原始請求中使用的方法;
301
(永久重定向)和302
(找到)不會改變大部分時間的方法,雖然較老的用戶代理可能(所以你基本上不知道)。
所有使用這些狀態(tài)碼的響應(yīng)都會發(fā)送一個Location
標題。
除重定向響應(yīng)之外,具有201
(創(chuàng)建)狀態(tài)的消息還包含Location
標題。它表示新創(chuàng)建的資源的 URL。
Location
和Content-Location
不同:Location
指示重定向的目標(或新創(chuàng)建的資源的 URL),而Content-Location
指示在內(nèi)容協(xié)商發(fā)生時用于訪問資源的直接 URL,而不需要進一步的內(nèi)容協(xié)商。Location
是與響應(yīng)關(guān)聯(lián)的頭部,Content-Location
與返回的實體關(guān)聯(lián)。
Header type | Response header |
---|---|
Forbidden header name | no |
Location: <url>
<url> 相對于(請求 URL)或絕對 URL。
Location: /index.html
Specification | Title |
---|---|
RFC 7231, section 7.1.2: Location | Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content |
Feature | Chrome | Firefox | Edge | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic Support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Feature | Android | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
---|---|---|---|---|---|---|---|
Basic Support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Content-Location
Status of responses including a Location
header: 201
, 301
, 302
, 303
, 307
, 308
.