I’m handling 404 error as follows –
// in .htaccess
ErrorDocument 404 /404.php
It works nicely.
But I would like to display the original URL he requesting. I am trying the following in my 404.php
–
echo $_SERVER['REQUEST_URI']; //but it shows mysite/404.php
echo $_SERVER['HTTP_REFERER']; // but it shows Undefined array key "HTTP_REFERER"
Any help to show the requesting URL in 404.php
page?
2
Answers
You can use mod_rewrite in .htaccess insteed. Your example with referer not working correct, because Apache2 makes redirect, not php.
For example in htaccess (mod rewrite should be turned on in apache config) something like this:
In this case, when you request, you will not receive a redirect, but a response from this address, but with an html error.
You can edit htacces
http://www.javascriptkit.com/howto/htaccess2.shtml
and then use on 404.php the following code