tech talk

The HOSTS File

Domain propagation sucks. I mean waiting 7-48 hours (which, in my experience, is a total hoax) so that you’re site’s domain becomes active is totally frustrating. Moving a website from our test server to the production server will still means that we have to check several things (configuration files, database, files, etc.), and the most convenient way to check this is to see if your “live” site is running perfectly. Some Administration Panel like Plesk has a “Site Preview” feature that allows you to, well, preview your site. It’s not totally effective since the URL becomes cryptic and you don’t know what’s happening under the hood.

I learned this trick from one of my officemates: the HOST file. Actually, it’s like tricking your browser to look on a specified NameServer (which in this case your deployment server). HOSTS file is located in:

 \WINDOWS\system32\drivers\etc\

Open it with any text editor. Here you will find tab-separated, value pairs like the one below:

# This is a comment and btw, this explains why localhost points to 127.0.0.1
127.0.0.1       localhost

Add the domain of your site and the IP of your server. Restart your browser and Voila! A sneak “live” preview of your website! Don’t forget to remove (or at least comment) it when the site goes live!

Comments

jokiz said:

it's also a hack for network admins who can't fix the darn dns server

# June 12, 2007 5:48 AM

man_at_the_third_row said:

At first, I thought it's for IE only but I was surprized that its working in FF too.

# June 13, 2007 4:09 AM