404 header - HTTP 1.0 or 1.1?

keithjgrant picture keithjgrant · May 5, 2010 · Viewed 50.4k times · Source

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 really been using HTTP 1.1 for over a decade? Is there any reason not to send HTTP/1.1 404 Not Found instead?

(Not that it matters all that much... I'm mostly just curious.)

Answer

DanMan picture DanMan · Sep 30, 2011

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.