Setting up a Host File - Faking URLs

Steve picture Steve · Mar 2, 2011 · Viewed 26.2k times · Source

I'm trying to set up my development instances so that I can fake some urls that I own. My website has a number of url's and depending on the one you visit my site will act differently based on the domain..

ive edited my C:\WINDOWS\system32\drivers\etc\hosts File to contain something like below

127.0.0.1       localhost
127.0.0.1   SomeDomain.com
127.0.0.1   MyDomain.com

Now if I visit localhost everything works fine but when i try visit SomeDomain.com or MyDomain.com it produces couple different messages depending on browsers

Firefox - "Bad Request (Invalid Hostname)" Chrome - Asked for a username/password and just hitting on (not entering anything) products same result as firefox

IE6- "The page cannot be displayed"

any ideas?

Answer

Jason Crease picture Jason Crease · Mar 2, 2011

Your HOSTS file looks good. Also try adding the www version of each one, e.g.: 127.0.0.1 localhost 127.0.0.1 SomeDomain.com 127.0.0.1 www.SomeDomain.com etc

However, the problem is probably the setup of the web server. If you're using IIS, the problem probably is that you haven't set up host headers correctly.