Editing Your Hosts File In Windows

Andrew Nacin mentioned here at WordCamp San Francisco 2011 where your hosts file is on Mac (and Linux), but I thought I’d point out where your hosts file is on Windows and how to change it so that you can point domain names to your local computer.

The easiest solution is to create a shortcut that will open Notepad and then tell it to open your hosts file. Right-click your desktop and select New → Shortcut. Paste the following into the field that pops up:

%windir%\system32\notepad.exe %windir%\System32\drivers\etc\hosts

Once you’re done creating the shortcut, right-click it and select “Properties”. Under the “Shortcut” tab is an “Advanced” button. Clicking it will show a checkbox for “Run as administrator”. This is important because otherwise you won’t be able to save your changes as the file is a protected one.

Opening it will show a little documentation and some examples. If you want to add your own, just add it to the bottom in this format:

	127.0.0.1	yourdomain.com

Saving the file and then visiting the domain in your browser will now show you files served by your local development environment. Note: a hard refresh may be required to due to your browser’s DNS cache. This can be accomplished by pressing control and F5.

This post was updated to recommend using a shortcut instead of manually opening Notepad as an administrator.