
When moving a website, it is sensible to check it before everyone else sees it.
DNS changes can take time to propagate. Once a domain points to new hosting, visitors may start reaching the new version of the site. If you want to test first, one option is to edit the hosts file on your own computer.
This lets your computer load the website from the new server while the rest of the world still sees the current live site.
What is the hosts file?
The hosts file is a local file on your computer that can map a domain name to a specific IP address.
Normally, your computer asks DNS where a domain should point. A hosts file entry overrides that lookup for your machine only. It does not affect other visitors, search engines or the public DNS record.
That makes it useful for testing website migrations.
When this is useful
Editing the hosts file can help when you are moving a website to new hosting, checking a redesign before launch, testing SSL and site paths on the new server, confirming images, forms and logins work correctly or reviewing a site before DNS is changed.
It is especially useful when temporary preview URLs do not show a site accurately.
What you need
You will need the new server IP address and the domain name you want to test.
The hosts file entry usually follows this pattern:
123.123.123.123 example.co.uk
123.123.123.123 www.example.co.uk
Replace the IP address and domain with your own details.
Editing the file
On Windows, the hosts file is usually found at:
C:\Windows\System32\drivers\etc\hosts
You normally need to open your text editor as Administrator before editing it.
On macOS and Linux, the hosts file is usually:
/etc/hosts
You may need administrator permissions to save changes.
Test carefully
After saving the hosts file, clear your browser cache or open a private window. You may also need to flush your DNS cache.
Then visit the domain and check the site as thoroughly as possible. Look at pages, menus, images, forms, checkout flows, logins, redirects and SSL. If anything breaks, fix it before changing public DNS.
Remove the entry afterwards
Once testing is complete, remove the hosts file entry or comment it out.
If you leave it in place, your computer may continue to load the old test destination even after public DNS has changed. That can make troubleshooting confusing later.
The hosts file is a simple tool, but it is a useful way to preview a website move with more confidence.