For faster navigation, this Iframe is preloading the Wikiwand page for HTTP 307.

HTTP 307

307 Temporary RedirectHTTP协议中的一个状态码(Status Code)。可以理解为一个临时的重定向[1]

但该响应代码与302重定向有所区别的地方在于,收到307响应码后,客户端应保持请求方法不变向新的地址发出请求。[2]

引入

虽然RFC 1945RFC 2068规范不允许客户端在重定向时改变请求的方法,但是很多现存的浏览器在收到302响应时,直接使用GET方式访问在Location头部中规定的URI,而无视原先请求的方法。[3]

因此,状态码307被添加了进来,用以明确伺服器期待客户端进行何种反应。[4]

特征

根据RFC 2616定义:

  • 响应实体必须带有一个HTTP Location头部来指示新地址。
  • 如果一个客户端有链接编辑能力,其应当把所有的引用链接重定向到新的URL上。
  • 除非带有Cache-Control或Expires头部,否则该响应不能被缓存。
  • 除非请求方法是HEAD,否则响应实体应该包含一个小型的超文本,标注一个超链接到新的URL。
  • 如果是除了GET和HEAD之外的请求方法,客户端必须在重定向之前询问用户。

示例

以GET方式请求

GET /index.php HTTP/1.1
Host: www.example.org

伺服器回应:

HTTP/1.1 307 Temporary Redirect
Location: https://www.example.org/

伺服器配置

这是一个例子,展示如何使用Nginx返回307重定向:

location /old/url/ {
    return 307 /new/url;
}

这是使用PHP实现307重定向的方式:

<?php
header("HTTP/1.1 307 Temporary Redirect");
header("Location: http://example.com/newpage.html");
exit();
?>


用途

  • 该响应码被用于Chrome,用来在本地对已经缓存的HSTS站点进行重定向。[5]
  • 该响应码也常用于客户端发出PUT请求,但非上传具体文件时,伺服器向客户端返回确认用的文本消息。[2]

参见

参考文献

  1. ^ HTTP/1.1: Status Code Definitions. [2017-06-30]. (原始内容存档于2010-03-16). 
  2. ^ 2.0 2.1 307 Temporary Redirect. Mozilla Developer Network. [2017-07-04]. (原始内容存档于2017-07-02). 
  3. ^ Reference of method redirect_to in Ruby Web Framework "Ruby on Rails". It states: The redirection happens as a "302 Moved" header unless otherwise specified.. [2012-06-30]. (原始内容存档于2012-07-05). 
  4. ^ Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content, Section 6.4. IETF. [2014-06-12]. (原始内容存档于2017-05-25). 
  5. ^ Understanding the "Fake 307" redirects in Chrome. cemper.academy. [2017-07-04]. (原始内容存档于2017-07-13). 

外部链接

{{bottomLinkPreText}} {{bottomLinkText}}
HTTP 307
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?