404 header - HTTP 1.0 or 1.1?

前端 未结 6 1633
心在旅途
心在旅途 2020-11-30 07:54

Why does almost every example I can find (including this question from about a year ago) say that a 404 header should be HTTP/1.0 404 Not Found when we\'ve real

6条回答
  •  独厮守ぢ
    2020-11-30 08:26

    In PHP you should probably use:

    header( $_SERVER['SERVER_PROTOCOL']." 404 Not Found", true );
    

    or even better

    header( $_ENV['SERVER_PROTOCOL']." 404 Not Found", true );
    

    (if supported) and thus leave it to the web-server which protocol to use.

    Actually, if you pass the status code as 3rd parameter, you can pass whatever you want in the 1st one, as long as it's not empty, and PHP will do the rest. See http://php.net/header

    header("foobar", true, 404 );
    

    Also: You can't request a certain protocol version from the client-side since the transaction is hop-to-hop based, and not end-to-end. The server and your browser may very well use HTTP/1.1, but if a proxy inbetween is using only HTTP/1.0, that's what you will see from your client.

提交回复
热议问题