简体   繁体   English

HTTP 301和308状态代码有什么区别?

[英]What's the difference between HTTP 301 and 308 status codes?

What's the difference between HTTP 301 and 308 status codes? HTTP 301308状态代码有什么区别?

  • 301 (Moved Permanently): This and all future requests should be directed to the given URI. 301 (永久移动):此请求和所有以后的请求都应定向到给定的URI。

  • 308 (Permanent Redirect): The request and all future requests should be repeated using another URI. 308 (永久重定向):应使用另一个URI重复该请求和所有以后的请求。

They seem to be similar. 他们似乎很相似。

An overview of 301 , 302 and 307 的概述301302307

The RFC 7231 , the current reference for semantics and content of the HTTP/1.1 protocol, defines the 301 (Moved Permanently) and 302 (Found) status code, that allows the request method to be changed from POST to GET . RFC 7231是HTTP / 1.1协议的语义和内容的当前参考,它定义了301 (永久移动)和302 (已找到)状态码,该状态码允许将请求方法从POST更改为GET This specification also defines the 307 (Temporary Redirect) status code that doesn't allow the request method to be changed from POST to GET . 该规范还定义了307 (临时重定向)状态码,该状态码不允许将请求方法从POST更改为GET

See more details below: 在下面查看更多详细信息:

6.4.2. 6.4.2。 301 Moved Permanently 301永久移动

The 301 (Moved Permanently) status code indicates that the target resource has been assigned a new permanent URI and any future references to this resource ought to use one of the enclosed URIs. 301 (永久移动)状态码表示已为目标资源分配了新的永久URI,以后对该资源的任何引用都应使用其中的一个URI。 [...] [...]

Note: For historical reasons, a user agent MAY change the request method from POST to GET for the subsequent request. 注意:由于历史原因,用户代理可以针对后续请求将请求方法从POST更改为GET If this behavior is undesired, the 307 (Temporary Redirect) status code can be used instead. 如果不希望出现这种情况,可以改用307 (临时重定向)状态代码。

6.4.3. 6.4.3。 302 Found 找到302个

The 302 (Found) status code indicates that the target resource resides temporarily under a different URI. 302 (已找到)状态代码指示目标资源临时位于其他URI下。 Since the redirection might be altered on occasion, the client ought to continue to use the effective request URI for future requests. 由于重定向有时可能会更改,因此客户端应继续将有效请求URI用于将来的请求。 [...] [...]

Note: For historical reasons, a user agent MAY change the request method from POST to GET for the subsequent request. 注意:由于历史原因,用户代理可以针对后续请求将请求方法从POST更改为GET If this behavior is undesired, the 307 (Temporary Redirect) status code can be used instead. 如果不希望出现这种情况,可以改用307 (临时重定向)状态代码。

6.4.7. 6.4.7。 307 Temporary Redirect 307临时重定向

The 307 (Temporary Redirect) status code indicates that the target resource resides temporarily under a different URI and the user agent MUST NOT change the request method if it performs an automatic redirection to that URI. 307 (临时重定向)状态代码指示目标资源临时位于其他URI下,并且如果用户代理执行到该URI的自动重定向,则它不得更改请求方法。 Since the redirection can change over time, the client ought to continue using the original effective request URI for future requests. 由于重定向会随时间变化,因此客户端应继续将原始的有效请求URI用于将来的请求。 [...] [...]

Note: This status code is similar to 302 (Found), except that it does not allow changing the request method from POST to GET . 注意:此状态码类似于302 (已找到),不同之处在于它不允许将请求方法从POST更改为GET This specification defines no equivalent counterpart for 301 (Moved Permanently) ( RFC 7238 , however, defines the status code 308 (Permanent Redirect) for this purpose). 该规范没有为301 (永久移动)定义任何等效的副本(但是RFC 7238为此定义了状态码308 (永久重定向))。

The need for 308 需要308

The RFC 7238 has been created to define the 308 (Permanent Redirect) status code, that is similar to 301 (Moved Permanently) but does not allows the request method to be changed from POST to GET . 已创建RFC 7238来定义308 (永久重定向)状态代码,该状态代码与301 (永久移动)相似,但不允许将请求方法从POST更改为GET

The 308 status code is now defined by the RFC 7538 (that obsoleted the RFC 7238 ). 308状态代码现在由RFC 7538 (已废弃RFC 7238 )定义。

3. 308 Permanent Redirect 3. 308永久重定向

The 308 (Permanent Redirect) status code indicates that the target resource has been assigned a new permanent URI and any future references to this resource ought to use one of the enclosed URIs. 308 (永久重定向)状态码表示已为目标资源分配了新的永久URI,并且对该资源的任何将来引用都应使用随附的URI中的一个。 Clients with link editing capabilities ought to automatically re-link references to the effective request URI to one or more of the new references sent by the server, where possible. 具有链接编辑功能的客户端应在可能的情况下自动将对有效请求URI的引用重新链接到服务器发送的一个或多个新引用。 [...] [...]

Note: This status code is similar to 301 (Moved Permanently), except that it does not allow changing the request method from POST to GET . 注意:此状态码类似于301 (永久移动),不同之处在于它不允许将请求方法从POST更改为GET

Se we have the following: 硒,我们有以下内容:

                                                             +-----------+-----------+
                                                             | Permanent | Temporary |
+------------------------------------------------------------+-----------+-----------+
| Allows changing the request method from POST to GET        | 301       | 302       |
+------------------------------------------------------------+-----------+-----------+
| Doesn't allow changing the request method from POST to GET | 308       | 307       |
+------------------------------------------------------------+-----------+-----------+

Choosing the most suitable status code 选择最合适的状态码

Michael Kropat put together a set of decision charts that helps to determine the best status code for each situation. Michael Kropat整理了一组决策图 ,可帮助确定每种情况的最佳状态代码。 See the following for 2xx and 3xx status codes: 有关2xx3xx状态代码,请参见以下内容:

选择2xx或3xx状态代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM