404 OK ?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am using the following bit of code at the very top of my pages to send a
404 Not Found error when people try to access any URL with a query string
in it.

$url_string = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

if (strstr($url_string, '?')) {
  header("HTTP/1.0 404 Not Found");
  echo <<<HTML
      <title>404 Not Found</title>
      <h1>Not Found</h1>
      The requested URL was not found on this server.

These are the headers that get sent back to the browser -- look at the
first line:

HTTP/1.x 404 OK
Date: Sun, 30 Apr 2006 11:13:37 GMT
Server: Apache/1.3.33 (Unix)
X-Powered-By: PHP/4.4.2
Keep-Alive: timeout=2, max=200
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html

But for the missing favicon (which really does not exist) I get a regular
404 error message:

HTTP/1.x 404 Not Found  

What is a "404 OK" header and why isn't it sending the "Not Found" header?
I am trying to get it to send a regular 404 Not Found header.  

Re: 404 OK ?

Are you using FastCGI?
Did you check the server's error log?

HTTP/1.x 404 OK

404 is for the user agents. "OK" or any other text is for humans to
read so it doesn't matter at all.

So far, google refered me to these threads:

Have a look.

Re: 404 OK ?

On Sun, 30 Apr 2006 05:57:32 -0700, Drakazz wrote:

Quoted text here. Click to load it

Thanks, I will read those links.

I have some URLs indexed by Google -- hundreds of dynamic URLs that don't
exist.  I'm trying to send a 404 when they are requested, but it's not
working.  Google is not dropping the URLs even after a couple of months of
those "404 OK" errors and use of the "automatic removal tool" (which is
now down).

So I wonder if that "404 OK" message is being interpreted correctly by the
search engines.  The robots.txt file to block spidering of dynamic URLs is
not working either so I'm not sure what is going on.  I think Google has a
lot of bugs.  I just checked my sitemap and it says that it can't find my
robots.txt file, but it is there and accessible by my browser.

Re: 404 OK ?


Quoted text here. Click to load it

  According to RFC2616 the x must be a digit.

  The 'OK' (called a reason phrase) is for human consumption.  Your
browser would still take this as a 404.  RFC2616 section 6.1.1:


  In the status line you wrote, your HTTP version is 1.0, but the
headers your server sends are only defined under 1.1.  What happens if
you change your status line to read:

HTTP/1.1 404 Not Found


Site Timeline