HTTP 重定向代码之间的区别 [英] Difference between HTTP redirect codes

查看:25
本文介绍了HTTP 重定向代码之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不清楚各种 HTTP 3XX 重定向代码之间的区别.是的,我已经阅读了规范,但这里的标准和实际实践之间似乎存在一些差异.

The differences between the various HTTP 3XX redirect codes are not clear to me. Yes, I've read the spec, but there seems to be some discrepancy between the standard and actual practice here.

301 重定向代码似乎很清楚:这意味着资源已永久移动到另一个 URI,并且未来的请求应使用该 URI.

The 301 redirect code seems clear enough: This means the resource was permanently moved to another URI, and future requests should use that URI.

而且 307 重定向代码似乎也很清楚:这意味着重定向是临时的,以后的请求仍应使用原始 URI.

And the 307 redirect code also seems clear: it means the redirect is temporary, and future requests should still use the original URI.

但我不知道 302303 之间有什么区别,或者为什么它们中的任何一个与 301 真的不同.看起来 302 最初的目的是作为一个 临时 重定向,(如 307),但实际上,大多数浏览器将其视为 代码>303.但是 303301 之间有什么区别?301 是否应该意味着重定向是永久性的?

But I can't tell what the difference is between 302 and 303, or why either of them are really different from 301. It seems that 302 was originally intended to be a temporary redirect, (like 307), but in practice, most browsers treated it like a 303. But what's the difference between a 303 and a 301? Is 301 supposed to mean the redirect is more permanent?

推荐答案

  • 301:永久重定向.对此资源发出后续请求的客户端应使用新的 URI.对于 POST/PUT/DELETE 请求,客户端应该自动遵循重定向.
  • 302:重定向原因不明.对此资源发出后续请求的客户端应该使用新的 URI.对于 POST/PUT/DELETE 请求,客户端应该自动遵循重定向.
  • 303:重定向原因不明.通常,操作已完成,在别处继续."对此资源发出后续请求的客户端应该使用新的 URI.对于 POST/PUT/DELETE 请求,客户端应该遵循重定向,但对后续请求使用 GET.
  • 307:临时重定向.资源可能会在稍后返回此位置.对此资源发出后续请求的客户端应使用旧 URI.对于 POST/PUT/DELETE 请求,客户端应该自动遵循重定向.
    • 301: Permanent redirect. Clients making subsequent requests for this resource should use the new URI. Clients should not follow the redirect automatically for POST/PUT/DELETE requests.
    • 302: Redirect for undefined reason. Clients making subsequent requests for this resource should not use the new URI. Clients should not follow the redirect automatically for POST/PUT/DELETE requests.
    • 303: Redirect for undefined reason. Typically, 'Operation has completed, continue elsewhere.' Clients making subsequent requests for this resource should not use the new URI. Clients should follow the redirect for POST/PUT/DELETE requests, but use GET for the follow-up request.
    • 307: Temporary redirect. Resource may return to this location at a later point. Clients making subsequent requests for this resource should use the old URI. Clients should not follow the redirect automatically for POST/PUT/DELETE requests.
    • 如果可以选择,我个人建议避免使用 302.许多客户端在遇到 302 时不遵循规范.对于临时重定向,您应该使用 303 或 307,具体取决于您希望在非 GET 请求上的行为类型.除非您需要 POST/PUT/DELETE 的替代行为,否则首选 307 到 303.

      I personally recommend avoiding 302 if you have the choice. Many clients do not follow the spec when they encounter a 302. For temporary redirects, you should use either 303 or 307, depending on what type of behavior you want on non-GET requests. Prefer 307 to 303 unless you need the alternate behavior on POST/PUT/DELETE.

      这篇关于HTTP 重定向代码之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆