With Apache and mod_rewrite you can designate a particular page or script to be served whenever some other page isn't found. This decision gets made before the 404 error handler ever gets invoked. Don't return a 404 then return the proper content. 404 is an error. Leave it an error.
Comment on Re: Changing http headers in cgi response
I would, but Your Mother already gave a good example in Re^3: Changing http headers in cgi response. There's no better advice I could give than to start there and to take specific questions about Apache and mod_rewrite to a forum where those are on topic (or the Chatterbox here if they are short and simple questions, since that's not really topic-limited).