Dev.to WebDev 🛠 Dev 👁 0 📖 3 min read

How to Test a Migrated WordPress Site Before You Change DNS

The scariest moment in a WordPress migration is changing DNS, because that is when real visitors start landing on the new server. The good news is that you can test the new site first, as if DNS had already changed, with

The scariest moment in a WordPress migration is changing DNS, because that is when real visitors start landing on the new server. The good news is that you can test the new site first, as if DNS had already changed, without anyone else noticing. The trick is a small edit to your own computer's hosts file.

Why bother

The new host usually gives you a temporary URL, and that is fine for a quick look. But a temporary URL is not your real domain. WordPress stores your domain in its settings, so redirects, absolute links, forms and some plugins can behave differently. Testing under the real domain shows you how the site will actually behave on cutover day.

What the hosts file does

Your computer normally asks DNS where a domain lives. The hosts file is a local override: if a domain is listed there, your computer uses that address and skips DNS. Only your machine is affected, so your visitors keep reaching the old server.

Step by step

  1. Get the new server's IP address. Your new host shows it in the account dashboard or in the welcome email. In this example we will use 203.0.113.10, which is a placeholder address reserved for documentation.
  2. Open the hosts file with admin rights.
    • Windows: C:\Windows\System32\drivers\etc\hosts
    • macOS and Linux: /etc/hosts
  3. Add one line with the IP, then your domain and the www version: 203.0.113.10 example.com www.example.com. Use your real domain, of course.
  4. Save the file and flush your DNS cache.
    • Windows: ipconfig /flushdns
    • macOS: sudo dscacheutil -flushcache followed by sudo killall -HUP mDNSResponder
    • Linux: depends on your system, and often a browser restart is enough.
  5. Restart your browser and open your domain. You should now be looking at the new server.

What to check while you are there

  • Click through the main pages and look for missing images or broken layouts.
  • Submit every form and confirm the email actually arrives.
  • Log in to the admin area and update a draft.
  • If you run a shop, walk through a full checkout in test mode.
  • Look at the browser console for mixed-content or blocked-resource warnings.
  • Check that redirects and permalinks behave correctly.

A command-line alternative

If you prefer not to edit the hosts file, curl can do a similar job for a single request. The --resolve option tells curl to connect to a specific IP for a given domain and port, for example curl --resolve example.com:443:203.0.113.10 https://example.com/ -I to look at the response headers. It is handy for checking redirects and status codes quickly.

Common surprises

Certificate warnings. Many hosts can only issue a free SSL certificate after the domain points to them. If your browser shows a warning during testing, that may be why. Ask your host how and when the certificate is issued.

The browser still shows the old site. Some browsers cache DNS or use encrypted DNS settings that bypass the hosts file. Restart the browser, try a private window, or check the browser's secure DNS setting.

A CDN or proxy sits in front. If your domain goes through a CDN, the hosts file override may route you around it. Remember that you are testing the origin server, not the full setup.

Email. The hosts file only changes where your browser looks for the website. It tells you nothing about mail. Check mailboxes and mail records separately.

Clean up

After DNS has switched and everything works, delete the line from the hosts file. Leaving it in place is a classic way to confuse yourself later, because you will keep seeing the new server even if something goes wrong with DNS.

If you want the full walkthrough of moving a site, here is a beginner-friendly guide on how to migrate a WordPress site.

What is the first thing you test on a freshly migrated site? Share it in the comments.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.