Setting up a new website on a new server or with a different hosting provider while the existing website is still live presents some challenges.
Https configuration
Firstly, to test https configurations configuration, you need to use the correct URL. Most hosting control panels supply a temporary URL, or you can alias your own spare domain, or sub-domain to the site.
If you try to test a https connection with a temporary URL different than the certificate is issued for, then you’ll get a certificate mismatch error. That may be enough to prove to you that the https binding is working, but doesn’t provide the best experience.
Redirections
If you have redirections configured in your web.config or .htaccess file, and they’re configured for your primary URL, then testing with a temporary URL may yield unpredictable results. Particularly if some rules refer to an absolute fully qualified URL, and others are relative to the root of the website, so are not dependent on the URL.
CMS Configuration
Some CMS’s like WordPress will often store the full URL in it’s settings or in data in the database. WordPress also stores image URL’s in it’s posts and pages using absolute URL’s.
If you set up a new hosting space with a temporary URL, then configure WordPress and start adding content, you’re going to be bound that that temporary URL, in the short term at least.
If you then point your live URL to the WordPress install and delete your temporary URL, you’ll have links to URL’s that don’t exist anymore, and you may even have issues where you’re unable to access your CMS admin area.
While they’re are plugins that you can use to work around these issues, they’re not always 100% effective.
The workaround
The easiest way to work around these issues is by using a well hidden system file called the hosts file. You can add a record to your hosts file that will override the DNS in your PC so that your URL will resolve to the IP of the new server, not the current live website.
In Windows this file is in the C:\Windows\System32\drivers\etc folder (on Mac it’s in the /etc folder). This file doesn’t have an extension. In Windows, you can edit it with Notepad, and on the Mac with “sudo nano /etc/hosts” via the Terminal
On a Windows PC, find Notepad in your start menu, then right click and select “Run as Administrator”. If you don’t do this, you won’t be able to save the file.
Open the hosts file at C:\Windows\System32\drivers\etc. Note that you will have to change the file extensions filter to “All Files (.)” in order to see it.
The file is documented and explains how to use it. To add a record, move to the bottom of the file and add the IP of the new server, then press the tab key, then add the domain/url (without http://). For example:
103.234.60.52 mydomain.com.au
Save the file, then visit mydomain.com.au in a browser, and you will be directed to the new server, so you can test or configure your new site. Everyone else will continue to see the existing live site.
To remove this workaround, remove the line from the hosts file and save again. If you want to retain this entry but disable it temporarily to get back to the live URL, add a hash to the beginning of the line.