HTTP 301和308状态代码有什么区别? [英] What's the difference between HTTP 301 and 308 status codes?
问题描述
HTTP 301
和308
状态代码之间有什么区别?
What's the difference between HTTP 301
and 308
status codes?
-
301
(永久移动):此请求和所有以后的请求都应定向到给定的URI.
301
(Moved Permanently): This and all future requests should be directed to the given URI.
308
(永久重定向):应使用另一个URI重复该请求和以后的所有请求.
308
(Permanent Redirect): The request and all future requests should be repeated using another URI.
它们似乎很相似.
推荐答案
301
,302
和307
的概述
RFC 7231 ,它是HTTP/1.1协议的语义和内容的当前参考,定义 301
(永久移动)和 307
(临时重定向)状态码,不允许将请求方法从POST
更改为GET
.
An overview of 301
, 302
and 307
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
. This specification also defines the 307
(Temporary Redirect) status code that doesn't allow the request method to be changed from POST
to GET
.
在下面查看更多详细信息:
See more details below:
301
(永久移动)状态代码表示目标
已为资源分配了新的永久URI,以及将来的任何资源
对此资源的引用应使用随附的URI之一. [...]
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. [...]
注意:出于历史原因,用户代理可以更改请求
后续请求从POST
到GET
的方法.如果这
行为是不希望的,307
(临时重定向)状态码
可以代替.
Note: For historical reasons, a user agent MAY change the request
method from POST
to GET
for the subsequent request. If this
behavior is undesired, the 307
(Temporary Redirect) status code
can be used instead.
302
(已找到)状态代码表示目标资源
暂时驻留在其他URI下.由于重定向
有时可能会更改,客户应继续使用
将来请求的有效请求URI. [...]
The 302
(Found) status code indicates that the target resource
resides temporarily under a different URI. Since the redirection
might be altered on occasion, the client ought to continue to use the
effective request URI for future requests. [...]
注意:出于历史原因,用户代理可以更改请求
后续请求从POST
到GET
的方法.如果这
行为是不希望的,307
(临时重定向)状态码
可以代替.
Note: For historical reasons, a user agent MAY change the request
method from POST
to GET
for the subsequent request. If this
behavior is undesired, the 307
(Temporary Redirect) status code
can be used instead.
307
(临时重定向)状态代码表示目标
资源临时驻留在其他URI和用户代理下
如果执行自动操作,则不得更改请求方法
重定向到该URI.由于重定向会随着时间而变化,
客户端应继续使用原始的有效请求URI
对于将来的要求. [...]
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. Since the redirection can change over time,
the client ought to continue using the original effective request URI
for future requests. [...]
注意:此状态代码与302
(已找到)相似,不同之处在于:
不允许将请求方法从POST
更改为GET
.这
规范没有为301
定义等效项(已移动
永久)( RFC 7238 定义状态代码308
(永久重定向)).
Note: This status code is similar to 302
(Found), except that it
does not allow changing the request method from POST
to GET
. This
specification defines no equivalent counterpart for 301
(Moved
Permanently) (RFC 7238, however, defines the status code 308
(Permanent Redirect) for this purpose).
需要308
已创建 RFC 7238 来定义 301
(永久移动),但不允许将请求方法从POST
更改为GET
.
The need for 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
.
308
(永久重定向)状态代码表示目标
已为资源分配了新的永久URI,以及将来的任何资源
对此资源的引用应使用随附的URI之一.
具有链接编辑功能的客户端应自动重新链接
对有效请求URI的引用
服务器在可能的情况下发送的一个或多个新引用. [...]
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.
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. [...]
注意:此状态代码类似于301
(永久移动),
除了不允许更改请求方法
POST
到GET
.
Note: This status code is similar to 301
(Moved Permanently),
except that it does not allow changing the request method from
POST
to GET
.
我们有以下内容:
+-----------+-----------+
| 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. See the following for 2xx
and 3xx
status codes:
这篇关于HTTP 301和308状态代码有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!