Sleezr
Buy Sleezr
WordPressredirectmigrationhosts filetroubleshooting

Fix WordPress Redirecting to the Live Site

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.

S

Sleezr Team

·3 min read
Fix WordPress Redirecting to the Live Site

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
3
Flush DNS, on Mac or on Windows.
4
Clear the browser host cache at chrome://net-internals/#dns (301s are cached aggressively).
5
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. Sleezr 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

Why does WordPress redirect to the live site on a new server?

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.

How do I stop WordPress redirecting so I can test the new server?

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.

Do I need to change siteurl in the database?

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

Why does the redirect still happen after editing hosts?

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

3 min read
WordPressDNSmigration

Test a WordPress Site Before DNS Propagation

Preview and test a WordPress site on a new server before DNS propagation using the hosts file. Map your real domain to the new IP, verify, then switch DNS safely.

S

Sleezr Team

Developer tools team

3 min read
WordPressmigrationhosting

Migrate WordPress to a New Server With No Downtime

Migrate WordPress to a new host with zero downtime: copy files and database, test on the new server via the hosts file before DNS, then switch and clean up.

S

Sleezr Team

Developer tools team

4 min read
localhosttroubleshootingERR_CONNECTION_REFUSED

Localhost Refused to Connect: How to Fix It

Fix "localhost refused to connect" (ERR_CONNECTION_REFUSED) in Chrome, on Windows, Mac, XAMPP and VS Code: check the server, the port, IPv6 vs IPv4, hosts file and firewall.

S

Sleezr Team

Developer tools team

4 min read
hosts filetroubleshootingDNS

/etc/hosts Not Working? Fixes for Windows, Mac & Linux

The hosts file is ignored or /etc/hosts changes do not take effect? Fix it on Windows, Mac and Linux: flush DNS, check syntax, IPv6, line endings, resolver caches and save permissions.

S

Sleezr Team

Developer tools team

3 min read
DNSChrometroubleshooting

Fix DNS_PROBE_FINISHED_NXDOMAIN (2026)

Fix DNS_PROBE_FINISHED_NXDOMAIN in Chrome and Edge: flush DNS, check the hosts file, reset DNS servers and clear the browser cache. Step-by-step solutions.

S

Sleezr Team

Developer tools team