WordPress Site Clone: The One Thing That Will Save You From Infinite Redirect Hell

You just copied a full WordPress site — files + MySQL dump — fired it up on a shiny new domain, and… nothing works.

  • Browser spins forever (infinite redirect loop)
  • CSS/JS/images all 404
  • wp-admin is a white screen of death

Classic symptom: the database is still shouting the old domain everywhere.

Here’s exactly what you need to do, in order of preference (fastest → most manual).

Method 1: WP-CLI (the nuclear option, do this first)

cd /var/www/your-new-site

# Hit both http and https variants because WP loves to store both
wp search-replace 'https://old-domain.com' 'https://new-domain.com' --all-tables --precise
wp search-replace 'http://old-domain.com'  'https://new-domain.com' --all-tables --precise

# Clean everything up
wp cache flush
wp rewrite flush --hard

Done in 10 seconds. Most reliable.

Method 2: Straight SQL (when WP-CLI isn’t available)

UPDATE wp_options 
SET option_value = 'https://new-domain.com'
WHERE option_name IN ('home', 'siteurl');

After running that:

  • Hard-refresh your browser (Ctrl+Shift+R)
  • Restart Nginx/Apache
  • If you use Redis/Object Cache → flush it

Method 3: wp-config.php override (quick & dirty, works even if DB is broken)

Drop these two lines at the very top of wp-config.php (right after <?php):

define('WP_HOME',    'https://new-domain.com');
define('WP_SITEURL', 'https://new-domain.com');

WordPress will automatically update the database on first load. Super handy for emergency rescues.

Pro tips from someone who’s cloned way too many sites:

  • Always use https in the new domain unless you have a very good reason not to.
  • Search-replace both http and https versions — WP stores them separately.
  • If you’re on a staging → production move, also run the search-replace on any serialized data (WP-CLI’s –precise flag handles most of it).
  • After everything works, remove the two define() lines from wp-config.php so future changes go through the normal Settings → General screen.

Do this once and your cloned site will behave like a real, healthy WordPress install instead of a haunted redirect zombie.

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注