📑 Table of ContentsHide / Show
The Danger of Standard SQL Search and Replace
When changing your domain name (e.g., from olddomain.com to newdomain.com), executing a naive SQL query like UPDATE wp_posts SET post_content = REPLACE(...) will corrupt theme options, widget settings, and Elementor templates. This is because WordPress stores PHP arrays in serialized format, where string character lengths are hardcoded (e.g., s:13:"olddomain.com").
Method 1: Using Better Search Replace (Recommended)
- Install and activate the free plugin Better Search Replace.
- Navigate to Tools → Better Search Replace.
- In Search for, enter
https://olddomain.com. - In Replace with, enter
https://newdomain.com. - Select all database tables, check Run as dry run, and click Run.
- Once verified, uncheck dry run and execute the live replacement safely.
Method 2: Command Line Migration with WP-CLI
For system administrators with SSH access, WP-CLI provides the fastest, zero-downtime serialized search-replace tool:
wp search-replace 'https://olddomain.com' 'https://newdomain.com' --all-tables --dry-run
wp search-replace 'https://olddomain.com' 'https://newdomain.com' --all-tables
wp cache flush
Setting Up Server-Level 301 Redirects
To preserve Google rankings and backlink authority, keep your old domain active for at least 12 months and redirect all traffic to the new domain via .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$ [NC]
RewriteRule ^(.*)$ https://newdomain.com/$1 [R=301,L]
⚡ Related WordPress Migration & Hosting Guides
- How to Migrate WordPress to Cloudways or VPS Hosting – Step-by-step zero-downtime server transfer and DNS cutover guide.
- How to Move WordPress from Localhost to Live Server – Migrate local test sites to live web hosting without losing SEO rankings.
- Best WordPress Hosting in Pakistan: Speed & Price Compared – Evaluate latency, PKR payment gateways, and TTFB server speeds.
- Top 10 Contact Form Plugins for WordPress in 2026 – Compare speed, anti-spam features, and field flexibility.
Handling Serialized PHP Data & Wildcard Redirects
One of the most catastrophic mistakes webmasters make when migrating to a new domain is running a plain SQL query like UPDATE wp_options SET option_value = replace(...) inside phpMyAdmin. WordPress stores countless theme customizer settings, widgets, and plugin configurations as serialized PHP strings.
Serialized strings record the exact character count of text (e.g. s:18:"https://oldurl.com"). If you change the URL to a new length without recalculating the integer counter, PHP fails to deserialize the data, instantly corrupting your widgets and site styling. Always utilize specialized tools like WP-CLI wp search-replace or the Better Search Replace plugin that automatically handle serialization recalculations.
Once database URLs are updated, configure permanent 301 wildcard redirection on your old server to preserve link equity and domain authority:
# Apache .htaccess 301 Wildcard Redirect
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com$ [NC]
RewriteRule ^(.*)$ https://newdomain.com/$1 [L,R=301]
Frequently Asked Questions
How long must I maintain 301 redirects on the old domain name?
Keep 301 redirects active for a minimum of 12 months. This allows Google and other search engines to transfer 100% of accumulated PageRank and backlinks to the new domain.
Will changing my WordPress domain cause a temporary drop in Google rankings?
Yes. A mild temporary fluctuation is normal for 2 to 4 weeks while search engine crawlers re-index your new URLs and verify 301 redirect mappings in Google Search Console.
Do I need to resubmit my XML sitemap after changing domain names?
Yes. Submit the new domain’s sitemap_index.xml immediately to Google Search Console and Bing Webmaster Tools, and initiate a Change of Address request in GSC.

