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
- The Windows Host file is called hosts (without any file extension) and can be found in the following directory: C:\Windows\System32\drivers\etc\
- To open the file, right click it and select ‘Open with’ option from the right click menu.
- Select notepad or any other text editor of choice to modify such file
- 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:
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
- Once you update the Windows hosts file, proceed with the testing.
- 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.