HTTP 301 和 308 状态代码有什么区别?
What's the difference between HTTP 301 and 308 status codes?
HTTP 301
和 308
状态码有什么区别?
301
(永久移动):此请求和所有未来请求都应定向到给定的 URI。
308
(永久重定向):应该使用另一个 URI 重复请求和所有未来的请求。
他们好像很像。
301
、302
和 307
概览
不允许将请求方法从POST
更改为GET
的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
(临时重定向)状态代码。
查看下面的更多详细信息:
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. [...]
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.
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. [...]
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.
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. [...]
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 has been created to define the 308
(Permanent Redirect) status code, that is similar to 301
(永久移动)但不允许将请求方法从 POST
更改为 GET
。
308
status code is now defined by the RFC 7538 (that obsoleted the RFC 7238).
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. [...]
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 |
+------------------------------------------------------------+-----------+-----------+
选择最合适的状态码
Michael Kropat put together a set of decision charts 有助于确定每种情况的最佳状态代码。请参阅以下 2xx
和 3xx
状态代码:
HTTP 301
和 308
状态码有什么区别?
301
(永久移动):此请求和所有未来请求都应定向到给定的 URI。308
(永久重定向):应该使用另一个 URI 重复请求和所有未来的请求。
他们好像很像。
301
、302
和 307
概览
不允许将请求方法从POST
更改为GET
的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
(临时重定向)状态代码。
查看下面的更多详细信息:
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. [...]Note: For historical reasons, a user agent MAY change the request method from
POST
toGET
for the subsequent request. If this behavior is undesired, the307
(Temporary Redirect) status code can be used instead.
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. [...]Note: For historical reasons, a user agent MAY change the request method from
POST
toGET
for the subsequent request. If this behavior is undesired, the307
(Temporary Redirect) status code can be used instead.
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. [...]Note: This status code is similar to
302
(Found), except that it does not allow changing the request method fromPOST
toGET
. This specification defines no equivalent counterpart for301
(Moved Permanently) (RFC 7238, however, defines the status code308
(Permanent Redirect) for this purpose).
需要308
RFC 7238 has been created to define the 308
(Permanent Redirect) status code, that is similar to 301
(永久移动)但不允许将请求方法从 POST
更改为 GET
。
308
status code is now defined by the RFC 7538 (that obsoleted the RFC 7238).
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. [...]Note: This status code is similar to
301
(Moved Permanently), except that it does not allow changing the request method fromPOST
toGET
.
我们有以下内容:
+-----------+-----------+
| 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 |
+------------------------------------------------------------+-----------+-----------+
选择最合适的状态码
Michael Kropat put together a set of decision charts 有助于确定每种情况的最佳状态代码。请参阅以下 2xx
和 3xx
状态代码: