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:
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:
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.
Pingback: Editing your hosts file in Windows | william p. davis
I would hope any and all web developers would know how to do this… but then again, so called “security experts” suck… :S
Thanks for the fantastic tip. A great timesaver too.
I wanted to add that in my experience, I either have to close the browser and reopen it if it cached the IP, or use a different browser.
Thank you for the summary of best practice for editing the hosts file in Windows. I’ve certainly been doing it wrong so far, by modifying the permissions on the security tab of file properties.
If you do a hard refresh (i.e. don’t use any caching) via control + F5 in your browser, then you should flush the DNS cache too and the modified hosts file should kick in.
In the back of my head I knew you’d blogged this, thanks for the great tip. 🙂
Pingback: Setting up Virtual Hosts with XAMPP running on Windows 7
Pingback: Just followed the rest of the Installing GitLab… « GlacierAgWeb
Nice tip, thanks. Might use it in my site if you don’t mind. I’ll credit you if I do.
Minor improvement (at least for me): Notepad++ will notice that the file is read-only and offer to re-open itself in admin mode.