Situation: You are moving your website to a new hosting provider, but have not yet pointed the DNS to the new server. Before you point the DNS there, you want to make sure the site is working on the new server. How can you test this when going to your website simply loads from your old provider?
You’ll need to trick your computer into thinking the domain name resolves to the new servers IP address.
To do this, you need to edit your hosts file.
The hosts file can be found in the following locations:
Windows 95 = C:windows
Windows 98 = C:\windows
Windows Me = C:\windows
Windows 2000 = C:windows\system32\drivers\etc
Windows XP = C:\windows\system32\drivers\etc
Windows NT = C:\winnt\system32\drivers\etc
Windows Vista = C:\windows\system32\drivers\etc
Windows 7 = C:\windows\System32\drivers\etc
Windows 8 = C:\windows\System32\drivers\etc
In Windows 7 and 8, you’ll need to run notepad as an administrator. To do this, click start, type notepad. Right click on notepad in the list of results, and click on Run as Administrator.
Once notepad opens, click file, then open. Browse to the directory listed above. If you do not see a file called hosts (with no extension) then you need to click the dropdown box in the lower right corner. It likely says “Text Documents (*.txt)”. Change this to “All Files (*.*)”. You should now see a file called hosts. Open this file.
At the bottom of this file, add 2 lines like this:
127.0.0.1 domain.com
127.0.0.1 www.domain.com
Replace the 127.0.0.1 with the IP address to your new server
Replace domain.com and www.domain.com with your domain name, both with and without the www.
Save the file. Now, when you access your site by domain.com or www.domain.com it will load from your new server. If you want to switch it back, simply delete those 2 lines from the file, and re-save the file.