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.
After writing
add one more header for any inexisting page on your site. It works, for sure.
Use these codes for 404 not found.
Here 404missing.html is your Not found design page. (it can be .html or .php)
No, it probably is actually working. It's just not readily visible. Instead of just using the
header
call, try doing that, then including404.php
, and then callingdie
.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:Then viewing the result with
curl -D /dev/stdout
reveals:Another reason may be if you add any html tag before this redirect. Look carefully, you may left DOCTYPE or any html comment before this line.
You could try specifying an HTTP response code using an optional parameter:
i think this will help you
content of .htaccess
ErrorDocument 404 /error.php
ErrorDocument 400 /error.php
ErrorDocument 401 /error.php
ErrorDocument 403 /error.php
ErrorDocument 405 /error.php
ErrorDocument 406 /error.php
ErrorDocument 409 /error.php
ErrorDocument 413 /error.php
ErrorDocument 414 /error.php
ErrorDocument 500 /error.php
ErrorDocument 501 /error.php
error.php and .htaccess should be put in the same directory [in this case]