In this post, we will show you the best way that we have found so far (with almost 20 years of experience) to open and test your website at your new hosting provider, while for everyone else your website still loads from your old hosting provider.
We know that changing hosting providers can be challenging if you do not want any downtime on your website. Things get even harder if you are using a content management system (CMS) or website software (i.e. WordPress) that stores most of the content based on the domain name/URL, and all that content is stored in a database.
Moving the website files and database from your old host to your new host may not be enough to get your website working properly as most hosting providers use different hardware, services, and settings. That is why, we always recommend that our customers test their website/s after we migrate the website/s to our servers and before the domain/s are pointed to our servers. The testing is done by tricking your computer into looking up your website from the new hosting provider instead of the global Domain Name System.
In general, the Domain Name System (DNS) stores various information about domain names on the Internet; most importantly the mapping of domain names to IP addresses. This allows you and everyone else to access websites by entering a domain name in the browser instead of a hard-to-remember IP address.
Every computer has a local DNS that is stored in a system file called “hosts”. The “hosts” file allows you to override the global DNS mapping on a local level and force your computer to resolve a domain name to another location. This is very handy if you are switching hosting providers or servers as you can access and test your website at the new location, while the website will continue to work from its original location for everyone else.
We will divide this post into three parts:
- Finding and opening your “hosts” file
- Understanding and editing the “hosts” file contents
- Clear your browser cache and cookies and purge your DNS cache
Find and open the “hosts” file
To access the “hosts” file, you will need to perform different actions depending on your computer’s operating system. That is why, we will provide step-by-step instructions for the most popular operating systems:
Understand and edit the “hosts” file contents
As we mentioned earlier, accessing the “hosts” file will depend on the operating system running on your computer; however, new custom mappings are added to the “hosts” file the same way across all operating systems. Generally, you have to enter an IP address and a hostname separated by an interval on a new line. So, if you want to see the website for domain1.com from the web server at 0.0.0.0 and the website for domain2.com from the web server at 255.255.255.255, you will need to add the following lines to your local “hosts” file:
0.0.0.0 domain1.com 255.255.255.255 domain2.com
Note: Of course, you will need to replace the example domain/s and IP address/es with your domain name and the IP address/es with the IP address of your hosting provider’s web server. We would recommend that you contact your hosting provider for the IP address of their web server as this information may not be easily accessible. With ICDSoft, the IP address of the web server is visible under “IP Addresses” from the “Information” section on the left side of the hosting Control Panel.
We added two custom mappings for hostnames domain1.com and domain2.com to our local hosts file; however, these mappings will not affect the hostnames with the WWW prefix (www.domain1.com and www.domain2.com). To resolve this, we can add two more lines to our hosts file, but there is an easier way – we can map the www and non-www hostnames to a single IP address by adding both of them after the IP address:
0.0.0.0 domain1.com www.domain1.com #mapping both domain1.com and www.domain1.com to 0.0.0.0
As you have probably seen in the example listed above, you can insert comments to your “hosts” file by adding the hashtag symbol (#) after a custom mapping or at the start of a new line:
# This is a comment 0.0.0.0 domain1.com #This is a comment 255.255.255.255 domain2.com #This is a comment
Clear your browser cache and cookies and purge your DNS cache
After you added the necessary custom mappings to your “hosts” file, you should clear your browsing cache and cookies and purge your DNS cache. This step is necessary as your browser and/or DNS cache may cause some website elements to load from the web server listed in the DNS and others from the web server specified in your “hosts” file.
Before we provide you with the steps to clear your browsing data, we should mention that this may log you out of websites, empty your online shopping carts, remove some of your address bar suggestions, etc.
You can access the window/menu that allows you to clear your browsing data on the most popular web browsers (Mozilla Firefox/Google Chrome/Apple Safari/Opera/Microsoft Edge) quite easily. All you need to do is simultaneously press the “CTRL” (Control), SHIFT“, and “DELETE” keys on your keyboard. If you are using macOS, you should press “CMD” (Command) instead of the “CTRL” (Control) key on your keyboard.
In the window/menu that appears, we would recommend that you choose to clear only the cache (cached data and files) and cookies (cookies and saved website data) and leave the other options unchecked.
It is worth mentioning that Google Chrome has its own DNS cache. To clear this cache, follow the steps listed below:
- Enter the following URL in the address bar of Google Chrome:
- Click on the “Clear host cache” button.
- Go to “Sockets” from the navigation menu on the left.
- Click on the “Flush socket pools” button.
The next and final step of the process is to flush the local DNS cache of your computer. Depending on your computer’s operating system, here is what you need to do:
This brings us to the end of this post. We covered everything you need to know about getting a website working from another location just for you. You learned how to find and use your “hosts” file, as well as clearing your browsers cache and sessions and your DNS cache.
As always, you can contact our friendly support team if you have any questions about the settings that you need to use in your “hosts” file.
If you learned something new, or if you liked this post, make sure to share it.