How to get page not found URL to my mail?

Hi all,
I want to know the Page not found URL’s of my site (is there any broken links in my site, i want to rectify it), which is to be visited by users, before showing/redirecting to the 404 custom page.

For that, i want to write some php script, to get the

$_SERVER[‘HTTP_REFERER’] and mail it to me.

But it is not working properly.

Can any one solve this problem…

Thanking you…

I… would say this needs the eye of someone with apache knowhow; you’ll need to rewrite the 404 page definition and… pass it the target URL on the query string? I dont even know if that’s possible.

Assuming AllowOverride is set to All in your apache config you can then set the error document using a .htaccess file (otherwise you’ll have to do it in your httpd.conf).

ErrorDocument 404 /path/to/not_found.phtml

Then just include your mail code in not_found.phtml.

edit: hadn’t read this properly, but $_SERVER[‘HTTP_REFERER’] should work. Don’t forget it’s only set if there is a referrer; if you access the script directly the referrer will not be set.


Except at that point isnt $_SERVER[‘REQUEST_URI’] = not_found.phtml? He’s trying to pass the attempted URL to the 404 page for emailing to himself.

Both $_SERVER[‘REQUEST_URI’] and $_SERVER[‘HTTP_REFERER’] work as expected.

    [REDIRECT_STATUS] => 404
    [HTTP_HOST] => localhost
    [HTTP_CONNECTION] => keep-alive
    [HTTP_REFERER] => http://localhost/playarea/test.html
    [HTTP_USER_AGENT] => Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.100 Safari/534.30
    [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    [HTTP_ACCEPT_ENCODING] => gzip,deflate,sdch
    [HTTP_ACCEPT_LANGUAGE] => en-GB,en-US;q=0.8,en;q=0.6
    [HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.3
    [PATH] => /usr/local/bin:/usr/bin:/bin
    [SERVER_SIGNATURE] => Apache/2.2.16 Server at localhost Port 80
    [SERVER_SOFTWARE] => Apache/2.2.16 
    [SERVER_NAME] => localhost
    [SERVER_ADDR] =>
    [SERVER_PORT] => 80
    [REMOTE_ADDR] =>
    [DOCUMENT_ROOT] => /var/www
    [SERVER_ADMIN] => webmaster@localhost
    [SCRIPT_FILENAME] => /var/www/playarea/not_found.phtml
    [REMOTE_PORT] => 57876
    [REDIRECT_URL] => /playarea/i_dont_exist
    [QUERY_STRING] => 
    [REQUEST_URI] => /playarea/i_dont_exist
    [SCRIPT_NAME] => /playarea/not_found.phtml
    [PHP_SELF] => /playarea/not_found.phtml
    [REQUEST_TIME] => 1308842418

Odd. When i do it on my XAMPP local installation, i get the 404 page in REQUEST_URI.

EDIT: Nevermind, I messed up the 404 htaccess. You are indeed correct (and a very handy piece of information to have learnt!)

Maybe different apache versions? Another option would be to do this:

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ /not_found.phtml


edit: didn’t notice your edit. I’ll leave that there though as could be useful if someone has AllowOverride set to None and does not have access to change httpd.conf