Home Blog WordPress Management How and Why to Use The Windows Hosts File

How and Why to Use the Windows Hosts File

How and Why to Use The Windows Hosts File

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.melapress.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.melapress.com to (localhost).

By adding such entry all the requests being sent from my computer to www.melapress.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:WindowsSystem32driversetc
  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:              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.              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.

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

2 thoughts on “How and Why to Use The Windows Hosts File

  1. 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

Leave a Reply

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

Stay in the loop

Subscribe to the Melapress newsletter and receive curated WordPress management and security tips and content.

Newsletter icon

It’s free and you can unsubscribe whenever you want. Check our blog for a taste.

Envelope icon