The best way to go is obviously to assign both domains to the same virtual webhost - nothing more to do.
If you do need to go down the described route, take a look at custom 404 handlers - basically you
- leave the complete server empty apart from a single script, that does not exist on the other server (e.g. my404hander.php)
- You dedicate this script as custom 404 handler in Apache
This leads to this control flow:
- A client requests
/some/url
- This is not found (server is basically empty), leading to 404 error
- Your custom handler is invoked
- it is now able to construct the coreseponding URL and do whatever it seems it should, e.g. send a redirect