Skip to content

How can I test my hosting before moving the domain?

Back to web hosting

Introduction:
In some cases it is useful to be able to view your website in advance on another server, think for example when moving a website.
You don't want unexpected errors to occur and cause the site to be temporarily down.
To prevent this, there is a way to point a domain name to another server without affecting the current operation of the domain name.
This option is mainly used for domain names that are being moved or have just been requested.
This way you can see in advance what the website will look like and make sure you won't be surprised afterwards.

Modify the hosts file on your computer
Every operating system (whether Windows, Linux or Mac OSX) has a hosts file.
The hosts file can be used to force a domain name to go to a particular ip address (this is what DNS does over the Internet).
It is then a prerequisite that you know the ip address of the server.
Once you modify your hosts file, it only applies to the device where you modified the hosts file, and not to other devices.
So for example, if you have two computers and one has its hosts file modified and the other does not, the results will be different. What you see after modifying the hosts file is not visible to the rest of the world.
The advantage of a hosts file is that you can specify to which server a certain domain should go.

An example:
For example, you can point google.nl to your own server (if you have created google.nl on the hosting). You can then show your own website on Google.nl without actually owning the domain name, but as already stated: this is only visible to yourself and not to the rest of the world.
So you can also use this to point your own domain name to another server without actually affecting the current operation of the domain name.
If you want the site to be as the Internet sees it again, remove the line from the hosts file.
Note that if you modify your hosts file, and do not restore it later, it may be that a domain is online with you and not with others, or vice versa, that a site is offline with you but not for the Internet, therefore make sure that after making the necessary changes you always modify your hosts file again and remove the lines.

How to edit my hosts file
To edit the hosts file, first you need to open the file with administrator rights.

In Windows:
Open Notepad with administrator privileges, you do this as follows:
Click on the Windows icon in the lower left corner with your left mouse button.
Search for Notepad.
Right click on the Notepad program and choose: Run as administrator.
Next, when Notepad is open at the top, go to file, open and go to "C:³".
Next to the File Name box is a selection field that says Text Documents (*.txt)
Change this to All files (*.*)
Then click on the file: hosts and click the Open button.


On Mac or Linux:
Open terminal (open your programs/applications folder and go to utilities, then open terminal)
In the terminal window enter the following command: sudo nano /etc/hosts (this only works if you have nano installed, otherwise you can use vi instead of nano, although nano works much easier). You will be prompted by the sudo command to enter your password, this is required and is similar to Windows administrator rights.

Once the file is opened you should already see a preview.
The example can help you with how to enter the hosts file.

Example: <the IP address of the other server> space <exampledomainname.ext>

If you want to point both the domain name itself and the www to the other ip address, then you need to create 2 lines for this you can put them below each other.

So a real example is:

81.254.55.22 exampledomain.com
81.254.55.22 www.voorbeelddomein.nl

Of course the ip address above is a made up ip address, and you need to replace this ip address with the ip address of the hosting server.
Then when you save the hosts file, and go to the domain name, the domain name will send your device to the ip address you specified in the hosts file.
You could also see this when you run a ping command, the domain name will respond with the ip address you specified in the hosts file. Back to web hosting