Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

header('HTTP/1.0 404 Not Found'); not doing anything

I have a 404.php file in my site's main directory and I was using header('Location: 404.php'); for a while until someone said that you should use header('HTTP/1.0 404 Not Found'); instead. So I replaced it with that and then added: ErrorDocument 404 /404.php to my apache config file and restarted the server but it doesn't work.

I tried different variations including ErrorDocument 404 404.php and ErrorDocument 404 mywebite/404.php but to no avail.

What I mean by doesn't work is that earlier when using header('Location: 404.php'); it would redirect to the 404.php file but when I replace it with header('HTTP/1.0 404 Not Found'); it seems to just skip over the line and not do anything. It most certainly is not redirecting. The reason I am calling for the redirect is because if a $_GET header value is not recognized the page should 404.

like image 496
John Smith Avatar asked Apr 04 '11 03:04

John Smith


People also ask

What is HTTP error 404 the requested resource is not found?

The HTTP 404 Not Found response status code indicates that the server cannot find the requested resource. Links that lead to a 404 page are often called broken or dead links and can be subject to link rot. A 404 status code only indicates that the resource is missing: not whether the absence is temporary or permanent.

What does the 404 status code in web browser indicate?

404 is a status code that tells a web user that a requested page is not available. 404 and other response status codes are part of the web's Hypertext Transfer Protocol response codes. The 404 code means that a server could not find a client-requested webpage.

What is 404 not found in PHP?

The 404 or Not Found error occurs when the user can communicate with the server but is unable to locate the requested file or resource.


1 Answers

No, it probably is actually working. It's just not readily visible. Instead of just using the header call, try doing that, then including 404.php, and then calling die.

You can test the fact that the HTTP/1.0 404 Not Found works by creating a PHP file named, say, test.php with this content:

<?php  header("HTTP/1.0 404 Not Found"); echo "PHP continues.\n"; die(); echo "Not after a die, however.\n"; 

Then viewing the result with curl -D /dev/stdout reveals:

HTTP/1.0 404 Not Found Date: Mon, 04 Apr 2011 03:39:06 GMT Server: Apache X-Powered-By: PHP/5.3.2 Content-Length: 14 Connection: close Content-Type: text/html  PHP continues. 
like image 69
icktoofay Avatar answered Sep 19 '22 13:09

icktoofay