Desired Scenario:
When a visitor arrives at a URL which normally returns a 404 error, the script will first automatically discover if there are any existing pages which would provide relevant content for that page and redirect the visitor from the 404 page to that matched relevant URL (like an automatic "I’m feeling lucky" search based on the text in the otherwise 404’ing URL).
If no existing pages are deemed relevant, then the "smart 404" system would deliver the user to the 404 page.
You can use this script: http://bobpeers.com/technical/404_redirection