Make use of your hosts file to fully test a new website before publishing or before the domain name has been pointed to your server.
Sure, you could develop the site on a different domain online / locally, test everything, then update the database sql when you move the site to a new environment. Cross your fingers? Hope you didn’t make a mistake : /
Instead, add a line like this one to your /etc/hosts file:
127.0.0.1 domain.co.uk www.domain.co.uk
Where the IP is either that of your hosting or 127.0.0.1 for your local server. The domain is the domain you will be using when the site goes live. This tells your computer to look at that IP when trying to resolve requests for that domain name.
Now you can view the site as it will be, log in, make whatever changes are required, test functionality like contact forms etc… Sleep easy in your bed while DNS does it’s thing.
You can find your hosts file here: c:\windows\system32\drivers\etc\hosts
Need more reasons why this is a better way to pre-launch test?
If you’re working with WordPress and you’re manually updating the database whenever you move your site from one environment to another, you may occasionally find data going missing – especially from text widgets. Here’s why:
WordPress stores many options as “serialized data”, which contains both the string content of things and their length. So when you modify the URL and the length changes, then the serialized data is no longer correct, and PHP rejects it.
So, make your publishing process safer and save yourself some time. Start using your hosts file.