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

查看:176
本文介绍了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.

但是我不知道 302 303 之间有什么区别,或者为什么它们中的任何一个与<$真的不同C $ C> 301 。似乎 302 最初打算成为临时重定向,(例如 307 ) ,但在实践中,大多数浏览器都将其视为 303 。但是 303 301 之间有什么区别? 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天全站免登陆