Posted by wd on 09/26/04 11:46
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.
<?php
$url_string = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
if (strstr($url_string, '?')) {
header("HTTP/1.0 404 Not Found");
echo <<<HTML
<html>
<head>
<title>404 Not Found</title>
</head>
<body>
<h1>Not Found</h1>
The requested URL was not found on this server.
</body>
</html>
HTML;
exit;
}
?>
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.
Navigation:
[Reply to this message]
|