Drupal 404 redirect to a custom PHP file
Ofcourse there is a module for this too.. !!!
Search 404 Module would help you achieve this

Instead of showing a standard &quot;404 Page not found&quot;, this module performs a search on the keywords in the URL
It also has Support for Custom Text and Title to be displayed in search404 pages