How and Why to Use The Windows Hosts File

Last updated on October 18th, 2014 by Robert Abela. Filed under WordPress Admin Tips

The Windows hosts file can be used to redirect requests from your computer to a website to another IP rather than the original IP or domain. In other words, if I want to run a test copy of the website www.wpwhitesecurity.com on my laptop, I configure a lightweight web server on my computer and simply add an entry in the Windows Host File to point www.wpwhitesecurity.com to 127.0.0.1 (localhost).

By adding such entry all the requests being sent from my computer to www.wpwhitesecurity.com are redirected to the web server running on my laptop rather than to the live website. This kind of scenario is ideal when testing website changes or new website features. Instead of making changes on the live website at the risk of breaking it, you can setup a local copy of the website using a XAMPP server to test the changes before applying them on the live website.

How to add entries to Windows Hosts file

  1. The Windows Host file is called hosts (without any file extension) and can be found in the following directory: C:\Windows\System32\drivers\etc\
  2. To open the file, right click it and select ‘Open with’ option from the right click menu.
  3. Select notepad or any other text editor of choice to modify such file
  4. To redirect all the traffic from your computer to your website to the test website on XAMPP web server running on your own computer, add the following line at the end of the hosts file:
 127.0.0.1              www.yourwebsite.com
 

In my case, to access my test copy of the website www.WP White Security.com running on my local computer, I add the below entry to the Windows hosts file.

127.0.0.1              www.WP White Security.com
  1. Once you update the Windows hosts file, proceed with the testing.
  2. Once ready from the testing, don’t forget to delete the entry from the Windows hosts file to be able to access the live website again.

WP White Security Blogger Tip: You might need to restart your web browser (such as Chrome) for the Windows Hosts file changes to take affect.

WordPress Hosting, Firewall and Backup

This Website is:

2 comments

FRITZ WILHELM VERBARG 31/03/2013

Hello,
I am new to web development and I need help. I would like to have 3 to 4 WordPress websites on my computer.
I have Windows 7, Xampp portable lite, Notepad++, and the most current version of WordPress.
My Xampp and WordPress are stored on an external harddrive. I have tried understanding this reconfiguring stuff, but I get lost.
For starters – Do I have to have my Xampp and WordPress on my “C” drive in order to have more than one site?
Do you know where I can get a step by step tutorial, for a novice?
Thank You for any possible help, Sincerely,
– Fritz

Robert Abela 31/03/2013

Hi Fritz.

Here is a tutorial for running multiple websites on Xampp; https://www.wpwhitesecurity.com/wordpress-tips-webmasters/multiple-websites-xampp/

Hope this answers your question and helps you get started. If you have any further queries, just drop us an email.

Leave a Reply

Your email address will not be published. Required fields are marked *