How to code custom 404 error handling? I was planning on using a new domain name when migrating my legacy site to Drupal. I already have the php script that will translate old urls into Drupal Urls (I'm not using pathauto for that).

Now there is a chance I have to keep showing content on the old domain (mainly for SEO purposes). This site won't have any login or write-backs at all, it basically just shows the content and link to the new site.

How would I intercept the 404's that Drupal would now generate, preferably at a very low bootstrap level since there could be tons of invalid requests?

Update:

Sounds like I could use hook_boot() to intercept every page request early and then have the query string parsed and redirected to the matching node/... page on the same site.

Or, similar to Fast404 I could add an include_once to settings.php and do the redirect there:

include_once('.sites/default/modules/myredirect_module/myredirect_module.inc');


Will there be a big difference between those two options?
You could just use the Fast404 module (if I'm understanding your question correctly).


  Drupal has expensive 404 errors. On an 'average' site with an
  'average' module load, you can be looking at 60-100MB of memory being
  consumed on your server to deliver a 404. Consider a page with a bad
  .gif link and a missing .css file. That page will generate 2 404s
  along with the actual load of the page. You are most likely looking at
  180MB of memory to server that page rather than the 60MB it should
  take.
  
  That's where Fast 404 comes in. This module combines a very common
  method of handling missing image/file 404 errors (discussed here and
  planned for Drupal 8) with a method created by dpardo (a co-maintainer
  of this project) to deliver super fast 404 error pages for both
  missing images and bad paths. Depending on which method of
  implementation you choose (aggressive or super aggressive) you can
  deliver 404 errors using less than 1MB of memory on your server.