During website migrations or before important deployments, it may be useful to preview your site on the new server before you've updated your domain's DNS in order to identify and troubleshoot potential bugs.
This article will show you a technique to test your website securely and completely by modifying a configuration file on your computer called the hosts file.
Hosts file format
The hosts file contains multiple lines. Each line will contain an IP address, followed by one (or multiple) spaces, follwed by a domain name. For example:
203.125.35.128 yourdomain.com
To correctly configure your hosts file. We recommend adding (or modifying, if you have already added them) 2 lines at the end of the file, one for your domain with and without the www, as follows:
203.125.35.128 yourdomain.com
203.125.35.128 www.yourdomain.com
Replace 203.125.35.128 with the actual IP address of your website. This can vary depending on your service. Please contact Web Hosting Canada's support team and ask if you do not know your IP address.
Replace yourdomain.com by your actual domain name.
How you edit your hosts file will vary depending on which operating system you are using on your computer:
For Windows 8, 10 or 11
Click on the Windows key
Enter Notepad in the search field
In the search results, right-click on Notepad and select Run as Administrator
In Notepad, open the file: C:\Windows\System32\Drivers\etc\hosts
Make your changes as described above and save your file.
Restart your browser and, optionally, empty its temporary files.
For Windows 7 or Vista
(also works on most older Windows versions as well)
Click on the Windows key or Start button
Click All Programs > Applications
Right-click on Notepad and select Run as Administrator
Click Continue to execute Notepad as an administrator
In Notepad, open the file: C:\Windows\System32\Drivers\etc\hosts
Make your changes as described above and save your file.
Restart your browser and, optionally, empty its temporary files
For Linux
Modify and save your changes with your preferred text editor (vi or nano). The file is called: /etc/hosts
For Mac
Open the Terminal application
Run the command: sudo nano /private/etc/hosts
If prompted, enter your administrative password
Modify the file as described above save your changes (Control + x, then y to confirm)
Now flush your Mac's DNS cache with: dscacheutil -flushcache
You're done!