ToggleHosts
Fix WordPress Redirecting to the Live Site

Fix WordPress Redirecting to the Live Site

3 min read

WordPress redirects to the live site when testing on a new server because the URL is hard-coded in the database. Fix it with the hosts file, no DB edits needed.

Manage hosts files without the terminal

ToggleHosts helps you manage environments visually on Windows, macOS, and Linux, with automatic DNS flush and backups.

WordPress redirects to the live site on a new server because the site URL is hard-coded in the database. WordPress stores siteurl and home in wp_options. When you reach the new server by IP, WordPress notices the host does not match and 301-redirects you to the live domain, so you end up on the old site. The clean fix is to map the real domain to the new server in your hosts file, no database edits required.

Fix WordPress redirecting to the live site

  1. Get the new server’s IP.
  2. Add it to your hosts file with the real domain:
TEXT
203.0.113.50 example.com www.example.com
  1. Flush DNS, on Mac or on Windows.
  2. Clear the browser host cache at chrome://net-internals/#dns (301s are cached aggressively).
  3. Reopen https://example.com in a fresh tab, it now loads the new server with no redirect.

Why this beats editing the database

Changing siteurl/home or running a search-replace to a temporary URL risks breaking the live site, polluting the database, and forcing a second migration of URLs later. The same logic applies when the URL is pinned with the WP_HOME/WP_SITEURL constants in wp-config.php: because you keep the real domain, there is nothing to rewrite for a staging or temporary URL. The hosts file leaves WordPress untouched and lets you preview the real production URL exactly as visitors will see it after the switch. See the full migration flow in migrate WordPress with no downtime.

If the redirect persists

  • Did you flush DNS? The OS may still resolve the old IP, re-run the flush.
  • Browser cached the 301? Clear the host cache and use a new tab or private window.
  • Missing www? Add both example.com and www.example.com.
  • HSTS forcing HTTPS to the old host? Test in a clean profile.

For the hard-coded-URL details, the wider preview workflow is in test a WordPress site before DNS propagation.

Avoid the trap entirely

The redirect-to-live problem comes down to a precise hosts mapping that must be added for testing and removed after go-live. ToggleHosts manages those migration entries as a toggleable environment and flushes DNS for you, so WordPress tests never bounce to the old site and no stale entry lingers afterward.

_Last tested: June 2026 with WordPress 6.x on Windows, macOS and Linux._

Sources and further reading

Also readTest a WordPress site before DNS propagation
Also readMigrate WordPress to a new server with no downtime
Share this article

Frequently Asked Questions

WordPress stores the site address in the database (siteurl and home in wp_options). When you visit the new server by IP, WordPress sees a different host and redirects to the configured live domain.

Map the real domain to the new server IP in your hosts file and flush DNS. WordPress then loads on the new server under its own URL, with no redirect.

No. The hosts file approach avoids editing wp_options, wp-config, or running search-replace, so you do not risk breaking the live site.

You likely did not flush DNS, the browser cached the redirect, or the entry is missing the www variant. Flush DNS, clear the browser host cache, and include both example.com and www.example.com.

Related Articles