PHP header('位置:' . $url) http1.0 vs http1.1 vs?
我正在使用 PHP 进行一些重定向,例如:
header('Location: '.$url);
但现在我需要使用其他一些状态代码进行一些重定向。
我应该为此使用http1.0还是http1.1。或者我们已经达到了 http2.0 或更高版本?
两者的状态代码是否相同?
假设我想使用状态代码 404(未找到)进行重定向。
我可以这样做吗:
header('HTTP/1.1 404 Not Found');
header('Location: '.$url);
或者有一个:
header('HTTP/2.0 404 Not Found');
header('Location: '.$url);
I'm doing some redirects using PHP, e.g.:
header('Location: '.$url);
But now I need to do some redirects with some other statuscodes.
Should I http1.0 or http1.1 for this. Or are we already at http2.0 or greater?
And are the status code the same for both?
So let's say I want to redirect using statuscode 404 (Not Found).
Can I just do:
header('HTTP/1.1 404 Not Found');
header('Location: '.$url);
Or is there a:
header('HTTP/2.0 404 Not Found');
header('Location: '.$url);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
一般来说,浏览器使用的是 HTTP 1.1(HTTP 1.0 已经很老了;并且不支持当今非常需要的几个有趣的功能)
HTTP 2.0?不存在这样的事情;-)
Don't hesitate to take a look at [Hypertext Transfer Protocol][1] -- and going through [**RFC 2616 - Hypertext Transfer Protocol -- HTTP/1.1**][2] can be a good idea.
是的,阅读本文可能需要一些时间——但如果您每天都在使用 HTTP,那么了解一点可能是个好主意;-)
Generally speaking, browsers are using HTTP 1.1 (HTTP 1.0 is quite old ; and doesn't support several interesting features which are pretty much required nowadays)
HTTP 2.0 ? There is no such thing ;-)
Don't hesitate to take a look at [Hypertext Transfer Protocol][1] -- and going through [**RFC 2616 - Hypertext Transfer Protocol -- HTTP/1.1**][2] can be a good idea.
Yes, it can take some time to read this -- but if you are working every day with HTTP, knowing a bit about it can be a good idea ;-)
没有HTTP/2.0; HTTP/1.1 是最新版本。
您可以使用
$_SERVER['SERVER_PROTOCOL']
的值以相同的协议版本进行响应:此时您应该意识到,如果响应是 HTTP/1.0,则 HTTP/1.1 标头字段可能将被忽略。
顺便说一句:Location标头字段 仅针对状态代码 201 和 3xx 定义:
There is not HTTP/2.0; HTTP/1.1 is the latest version.
You can use the value of
$_SERVER['SERVER_PROTOCOL']
to respond with the same protocol version:At this point you should be aware that if the response is HTTP/1.0 the HTTP/1.1 header fields probably will be ignored.
By the way: The Location header field is only defined for the status codes 201 and 3xx:
请参阅
header()
的第三个参数 用于发送特定状态代码:See the third parameter to
header()
for sending a specific status code:如果您发送
HTTP/1.0
还是HTTP/1.1
,这取决于您,因为对于您的目的来说,没有任何改变。Its up to you, if you send
HTTP/1.0
orHTTP/1.1
, because for your purposes nothing changed.使用
HTTP/1.1
。目前称为 HTTPbis 的 HTTP 的下一个版本将只是一个更新,仍然称为HTTP/1.1。Location:
标头独立于协议版本工作。请注意,并非所有Status:
号码都允许使用它们。只有范围 200-400 才应该使用它。对于 500 个错误,它肯定会被忽略。Use
HTTP/1.1
. The next version of HTTP currently known as HTTPbis will just be an update, and still be called HTTP/1.1.The
Location:
header works independently from the protocol version. Note that not allStatus:
numbers allow them. Only ranges 200-400 should use it. For 500 errors it will certainly be ignored.