Whenever an existing website is to be moved to a new web server, the question arises: How can I test or edit the new website while the associated domain still points to the old website? Let us take as an example mydomain.com. In the DNS records for mydomain.com (and normally also www.meinedomain.de) the IP address of the old server is entered, and all accesses via http://www.meinedomain.de are directed to the old server.
With a little trick, you can achieve that - only for you and not for the public http://www.meinedomain.de to the new server. DNS resolution, i.e. the assignment of a domain to an IP address, starts with the browser looking in the HOSTS file on the local computer to see if it finds an entry for the called domain. (Incidentally, in the early days of the internet, when there were no public name servers, this was the only way to get a DNS resolution. Every user had to enter and maintain all domains with the corresponding IP addresses in his HOSTS file himself).
So the solution is quite simple: You only have to make an entry in the HOSTS file on your computer that links the domain with the IP address of the new server. The entry itself is also quite simple, it consists of a single line that is best added to the end of the file. The line has the form
<IP-Adresse> <Domain> … <Domain>
The IP address can be followed by one or more domains, so if e.g. mydomain.com is to be moved to the server with the IP 126.96.36.199 the line
188.8.131.52 mydomain.de www.mydomain.de
can be appended to the local HOSTS file. However, there are usually practical problems in making this entry.
- Where can I find the local HOSTS file?
- How can I edit them?
- How can I save them?
On LINUX systems, the local HOSTS entries are found in the file /etc/hosts and can be edited with any text editor, e.g. vi or nano.
On Windows systems, the local HOSTS file is somewhat more hidden, and - depending on the Windows version - in different places. The best thing to do is to go to the Windows directory on the C: disk and then search for hosts (without file extension). On a Windows 7 32bit you will then find e.g.
The next problem is to edit this file. Windows blocks this - sensibly - for security reasons. One way is to run the Editor programme (usually found under Start -> All Programs -> Accessories) with extended rights. To do this, click on the icon Editor Click with the right mouse button and then Run as administrator select. Now you must allow the programme to make changes to the computer and then navigate to the directory in which hosts lies. Now another small hurdle: By default you see hosts not now, because the editor only Text files (*.txt) lists. So still on All files (*.*) change over, and then you can hosts into the editor.
The file is only a few lines long in its original state. Now simply add the desired line at the bottom and save. Here again a problem can occur: Many virus protection programmes do not allow changes to the local HOSTS file and prevent it from being saved. If this is the case, the setting in the virus protection programme must be changed so that hosts can also be saved. Here is the setting using AVIRA Professional Security as an example:
The catch with Protect Windows hosts file from changes must be removed.
Before the changed setting takes effect, all browser windows must be closed and the browser restarted. If everything has worked, the website will now appear on the new web server - but only on the computer on which these changes were made.
The fact that the browser has to be restarted can be used to view the old and the new website in parallel: Simply call up the website in one browser (e.g. Safari) before saving the change to the hosts (then the old website is visible in this browser), then save the change and call it up afterwards with another browser (e.g. Firefox). This does not work with several windows or instances of the same browser; you have to use different browser types.
Finally: After you have finished testing and editing the new website, don't forget to
- remove the changes to the HOSTS file again
- If necessary, reactivate the change lock for the HOSTS file in the virus protection programme.