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.