I can’t believe that this is not a solved problem by now, but my Google-fu is failing me. I’m looking for a decent, working extension for Chrome that can redirect a list of hosts to a different server while setting the Host: header to the right address. Everything I’ve found so far assumes that you’re running the servers on different urls. I’m using the same URL on different servers and don’t want to mess around with /etc/hosts.
Please tell me something exists to do this?
Hmm, my google-fu is strong today:
This one makes the point that what you really need is
a local proxy server configured to do your bidding:
But still one answer links to:
I’m currently considering setting up a solution involving using Apache on localhost as a forward proxy to itself. Then I can use a proxy switcher to do what I want. This approach seems to agree with your answer.
That extension only appears to modify the DOM to change links to point to the new server. The HTML will still come from the original server. I did find an extension that allowed you to modify your /etc/hosts in the browser, but you had to make the file world writeable. Unbelievable.
I suspect the reason why this isn’t possible in an extension is before it would be a bad idea to allow extensions to modify DNS responses.
Thanks for your help though.
The main reason for wanting to avoid changing the domain name between development and live is that the database contains references to the domains being served. As I plan on doing regular refreshes of development from live, updating these references could be a pain. I think I’ve found a working solution of using a proxy switcher (in this case SwitchySharp) to use the development webserver as a proxy server when I want to use the dev instance. This pretty much just works, although it wouldn’t surprise me if there were subtle corner cases I haven’t considered.
I usually use iptables DNAT rules to redirect the output to the desired IP address. That takes effect quickly and easily (no reloading proxies) and is transparent to the client.
One thing I haven’t tested (but which should work) is to use iptables rules based on UID so that I can have two browsers running as different users that see different versions of the web site.