Loading AI tools
HTTP回應狀態碼 来自维基百科,自由的百科全书
302 Found,原始描述短語為Moved Temporarily,是HTTP協議中的一個狀態碼(Status Code)。可以簡單的理解為該資源原本確實存在,但已經被臨時改變了位置;換而言之,就是請求的資源暫時駐留在不同的URI下[1],故而除非特別指定了緩存頭部指示,該狀態碼不可緩存。
對於服務器,通常會給瀏覽器發送HTTP Location頭部來重定向到新的新位置。
根據定義[2][3][4],該響應代碼的使用場景是,請求的資源暫時駐留在不同的URI下。
其特徵被定義為:
客戶端請求:
GET /blog HTTP/1.1
Host: www.example.com
第一種服務器回應,不帶緩存頭:
HTTP/1.1 302 Found
Location: https://www-temp.example.org/
第二種服務器回應,帶緩存頭:
HTTP/1.1 302 Found
Location: https://www-temp.example.org/
Cache-control: private; max-age=600
這是一個例子,展示如
^www\.(.*)$ [NC] RewriteRule ^ RewriteRule ^(.*)$ https://example.com/$1{{Dead link|date=2019年10月 |bot=InternetArchiveBot |fix-attempted=yes }} [R,L]
等價的Nginx配置方式:
location /old/url/ { return 302 /new/url; }
這是使用PHP實現HTTP 302重定向的方式:
<?php
header("HTTP/1.1 302 Found");
header("Location: http://example.com/newpage.html%5B%5D");
exit();
?>
雖然RFC 1945和RFC 2068兩個規範不允許客戶端在重定向時改變請求的方法,但是很多現存的瀏覽器將302響應視作為303響應 ,並且徑自使用GET方式訪問在Location中規定的 URI,而無視原先請求的方法,這是不規範的實現。[5]
Seamless Wikipedia browsing. On steroids.
Every time you click a link to Wikipedia, Wiktionary or Wikiquote in your browser's search results, it will show the modern Wikiwand interface.
Wikiwand extension is a five stars, simple, with minimum permission required to keep your browsing private, safe and transparent.