Henrik Erlandsson
Henrik Erlandsson

Reputation: 3831

Create ErrorDocument scripts that automatically report broken URLs

Is there an easy way to do this, in f.ex. .htaccess?

I've tried passing the request or request uri as parameter to a PHP file, but of course the ErrorDocument command is not a RewriteRule.

Ideally I'd just log it or send an email with the offending URL and tell the visitor that the webmaster has been notified. Email would be best since I'd be able to get notified immediately.

Upvotes: 1

Views: 50

Answers (1)

Justin Iurman
Justin Iurman

Reputation: 19016

Sure it is possible.
All you have to do is to put this line in your htaccess (for example, with 404 error)

ErrorDocument 404 /log.php

You can change the path to match its real location.

Then, in your php file, you can get the url with $_SERVER['REQUEST_URI']

Example: http://www.domain.com/unknown/url/does/not/exist
In this case: REQUEST_URI = /unknown/url/does/not/exist

Upvotes: 2

Related Questions