wp-config dynamic hostname in WP_HOME and WP_SITEURL

The obvious problem is that you are trusting user input (http headers) which makes your code suspicious from security POV.

Other then that, no real problems with it, but my experience is that such hacks have a tendency to just move whatever problem you are trying to solve this way to another place.