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:

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