skip to Main Content

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


  1. 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:

    RewriteEngine on
    RewriteRule ^/page.html /error404.html [L]
    

    In this case, when you request, you will not receive a redirect, but a response from this address, but with an html error.

    Login or Signup to reply.
  2. You can edit htacces
    http://www.javascriptkit.com/howto/htaccess2.shtml

    ErrorDocument 404 /404.php?url=%{REQUEST_URI}
    

    and then use on 404.php the following code

    $_GET['url']
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search