if (strstr($_SERVER['REQUEST_URI'],'index.php')){ header('HTTP/1.0 404 Not Found'); }
Why wont this work? I get a blank page.
if (strstr($_SERVER['REQUEST_URI'],'index.php')){ header('HTTP/1.0 404 Not Found'); }
Why wont this work? I get a blank page.
That is correct behaviour, its up to you to create the contents for the 404 page.
The 404 header is used by spiders and download-managers to determine if the file exists.
The page won't be indexed by google or other search-engines.
Normal users however don't look at http-headers and use the page as a normal page.
if (strstr($_SERVER['REQUEST_URI'],'index.php')){
header('HTTP/1.0 404 Not Found');
}
echo "<h1>404 Not Found</h1>";
echo "The page that you have requested could not be found."
exit();
If you look at the last two echo lines, that's where you'll see the content. You can customize it however you want.
If you want the server’s default error page to be displayed, you have to handle this in the server.
Your code is technically correct. If you looked at the headers of that blank page, you'd see a 404 header, and other computers/programs would be able to correctly identify the response as file not found.
Of course, your users are still SOL. Normally, 404s are handled by the web server.
The problem is, once the web server starts processing the PHP page, it's already passed the point where it would handle a 404
In addition to providing a 404 header, PHP is now responsible for outputting the actual 404 page.
A little bit shorter version. Suppress odd echo.
if (strstr($_SERVER['REQUEST_URI'],'index.php')){
header('HTTP/1.0 404 Not Found');
exit("<h1>404 Not Found</h1>\nThe page that you have requested could not be found.");
}