7 - Dynamically changing links based on environment
I don't think I would try to do this in Drupal. I would setup a small proxy server using Apache/mod_rewrite. You can rewrite your url's based on the source url. There is some good starter information at on the Apache doc site. There is also full on mod_proxy, but I think mod_rewrite would be sufficient for your use case.