Apache's ErrorDocument directive can come in handy. For example, this line in
your Apache configuration file:
ErrorDocument 404 /error.php
Can be used to redirect all 404 errors to a PHP script.
The following server variables are of interest:
- • $REDIRECT_ERROR_NOTES - File does not exist: /docroot/bogus
- • $REDIRECT_REQUEST_METHOD - GET
- • $REDIRECT_STATUS - 404
- • $REDIRECT_URL - /docroot/bogus
Don't forget to send a 404 status if you choose not to redirect to a real page.
<? Header('HTTP/1.0 404 Not Found'); ?>
Interesting uses
- • Search for closest matching valid URL and redirect
- • Use attempted url text as a DB keyword lookup
- • Funky caching