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 127.0.0.1 (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
- The Windows Host file is called hosts (without any file extension) and can be found in the following directory: C:WindowsSystem32driversetc
- 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:
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
- 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.
Melapress Blogger Tip: You might need to restart your web browser (such as Chrome) for the Windows Hosts file changes to take affect.
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
Hi Fritz.
Here is a tutorial for running multiple websites on Xampp; https://melapress.com/multiple-websites-xampp/
Hope this answers your question and helps you get started. If you have any further queries, just drop us an email.