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.
Locahl Team
Table of Contents
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:
203.0.113.50 example.com www.example.com3. 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 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.comandwww.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. Locahl 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._
Ready to simplify your workflow?
Stop wasting time with the terminal. Locahl lets you manage your hosts file in a few clicks, with automatic validation and no risk of errors.
- Intuitive visual interface
- Automatic DNS flush
- Multi-environment management
- Automatic backups
- JSON Import/Export
Reader Reviews
"Explained exactly why WordPress kept bouncing me to the live domain on the new server. Hosts file fixed it."
June 13, 2026
"No more search-replace gymnastics. Mapping the domain to the new IP let me test cleanly."
June 11, 2026
"Solved my redirect loop. A wp-config snippet for emergencies would be a nice extra."
June 9, 2026
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
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.
Locahl Team
Developer tools team
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.
Locahl Team
Developer tools team
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.
Locahl Team
Developer tools team
Fix "This site can’t be reached" on localhost
Fix "This site can’t be reached" / ERR_CONNECTION_REFUSED on localhost: check the server is running, the right port, IPv6 vs IPv4, the hosts file and firewall.
Locahl Team
Developer tools team
WordPress Local Development With a .test Domain (hosts file)
Set up a local WordPress site with a clean .test domain using the hosts file. Works with LocalWP, MAMP, XAMPP and Docker. Map the domain, flush DNS, configure WP.
Locahl Team
Developer tools team