If you are using Apache, I'd recommend setting a ErrorDocument 404 /local/url/to/script
instead. The custom error handler script
receives all pertinent information about the failed request or missing page.
The trickiest implementation of a 404 (Not found) error handler I know (not currently used in production, though) tries a number of alternate servers to locate the corresponding page. Very useful when migrating and combining web servers.