For those that don't know, your Window's "hosts" file can be used to map a domain name to an IP address to trick your browser into thinking routing requests for a particular domain to a different server.

This file is not typically needed in development, but if you ever need to map a domain to the IP address of a another server (i.e. a development server or QA server), then knowing how to edit this file may come in handy.

In Windows XP, this file is located here:

c:\windows\system32\drivers\etc\hosts

There are plenty of resources out there on how to edit this file, so I won't elaborate on that, but I wanted to point out a trick that is handy if you are editing this file on a regular basis.

Since the hosts file doesn't have a file extension, by default, you have to choose which program you would like to use to open it, when you double click on it. You can fix this annoying behavior by following these steps:

  1. Create a shortcut to the hosts file on your desktop.
  2. Right Click on the shortcut and choose properties.
  3. Before continuing, you may wish to change the ugly icon by clicking the "Change Icon" button.
  4. Next, edit the field called "Target" to say this:

    C:\WINDOWS\system32\notepad.exe 'c:\windows\system32\drivers\etc\hosts'

  5. Then click ok to save.

That's it, now double click the icon and it will open your hosts file in notepad.

Leave a Reply