为什么 "Not Modified" 是重定向(“3xx”)状态代码?

Why is "Not Modified" a redirection ("3xx") status code?

如果您对资源进行 GET 请求,那么您可以获得 Not Modified 响应以避免不必要的流量是非常有意义的。

问题是return代码为什么是304?这意味着它是一个 重定向 响应。在这种情况下,预期的重定向位置是什么?

我原以为它是 2xx 范围内的东西,因为它是 成功的 请求和有效答案。

参见RFC

它正在重定向到缓存中存储的数据副本。

请不要再使用过时的旧 RFC 2616 作为参考。 它已被 RFC 7230-35 完全废弃,它们共同定义了 HTTP 协议。


RFC 7231, there are several types of redirects and one of them is an implicit redirection to a cached resource, as indicated by the 304 状态代码中所述(突出显示是我的):

6.4. Redirection 3xx

The 3xx (Redirection) class of status code indicates that further action needs to be taken by the user agent in order to fulfill the request. [...]

There are several types of redirects:

  1. Redirects that indicate the resource might be available at a different URI, as provided by the Location field, as in the status codes 301 (Moved Permanently), 302 (Found), and 307 (Temporary Redirect).

  2. Redirection that offers a choice of matching resources, each capable of representing the original request target, as in the 300 (Multiple Choices) status code.

  3. Redirection to a different resource, identified by the Location field, that can represent an indirect response to the request, as in the 303 (See Other) status code.

  4. Redirection to a previously cached result, as in the 304 (Not Modified) status code.

见下文 304 status code is defined in the RFC 7232:

4.1. 304 Not Modified

The 304 (Not Modified) status code indicates that a conditional GET or HEAD request has been received and would have resulted in a 200 (OK) response if it were not for the fact that the condition evaluated to false. In other words, there is no need for the server to transfer a representation of the target resource because the request indicates that the client, which made the request conditional, already has a valid representation; the server is therefore redirecting the client to make use of that stored representation as if it were the payload of a 200 (OK) response.