WordPress Domain Moves That Do Not Corrupt Data
Move a WordPress site to a new domain safely: rehearse on a copy, use WP-CLI search-replace with a dry run, keep GUIDs, and verify before DNS changes.
You have a client’s WordPress site going to a new hostname, a SQL dump, a plugin or two you don’t fully trust, and a cutover window someone has already promised. It is tempting to open the dump in a text editor and find and replace the domain. That step can quietly ruin widgets, theme settings and builder data.
To move a WordPress site to a new domain without corrupting data, restore a copy of the database somewhere isolated, run a serialization-aware replacement (WP-CLI’s wp search-replace) with a dry run first, leave post GUIDs alone, then verify the copy before any traffic reaches it. A raw find and replace on the dump is the one thing to avoid, because PHP stores string lengths inside serialized values and changing the domain’s byte length makes those lengths wrong.
This post is for developers and small studios moving a self-hosted, single-site WordPress install. It covers the rewrite itself, the rehearsal, the subdomain and Multisite cases, and the checks around the DNS change. Registrar transfers and DNS-only connections get a short table at the start so you can tell which job you actually have.
- A domain change can mean rewriting URLs stored in the database. Changing only
homeandsiteurldoes not touch URLs embedded in content, widgets or theme settings. - Use
wp search-replacewith--skip-columns=guid, run--dry-runfirst, and never make the live database your first attempt. - Audit the table list before you apply. The default scope only reaches tables registered with WordPress, so some plugin tables can be missed.
- For big or busy sites, time the rehearsal on a recent copy and decide in advance how orders, comments and form entries made during the move will reach the new site.
- If serialized data breaks, restore from the clean pre-change backup and rerun on a copy. Don’t patch lengths by hand on the live database.
What are you actually changing when you move a WordPress site to a new domain?
Four different jobs all get called “moving a domain”: changing the public URL, moving hosts under the same URL, pointing a domain at a site, and transferring the registration. Only the first calls for rewriting stored URLs.
| The job | Database rewrite? | What you do |
|---|---|---|
| Public URL changes (old.example to new-site.example) | Yes, where old URLs are stored | The rest of this post. |
| Same URL, new host | Usually no | Copy files and database, set the new database credentials, repoint DNS. |
| Add a domain you own to a WordPress.com site | No | On a supported plan, open Domains in the Hosting Dashboard, choose “Use a domain name I own” and follow the setup. WordPress.com documents this, and you still renew the domain through your registrar. |
| Transfer a domain from Squarespace to WordPress.com | No | Turn off the domain lock, get the authorization code and enter it in the WordPress.com transfer flow. The Squarespace guide says a transfer leaves the website itself at Squarespace, so content is a separate move. |
If you only want a domain to show an existing site, set it up with your host and point DNS there. You can skip the registrar transfer. The first row is the one that needs the rest of this post.
On a self-hosted site, home is the public address and siteurl is where the WordPress application lives. The WP_HOME and WP_SITEURL constants in wp-config.php override those options at runtime without saving new values, per the wp-config handbook page. They do nothing for the old domain sitting inside post content. If either constant is set to the old address, update it in the copied config too.
Why does a plain search-replace break serialized data in WordPress?
PHP serialization writes each string’s byte length in front of the string, so replacing it with text of a different byte length without updating that number leaves a value PHP can no longer read.

The PHP source writes the length first and then copies exactly that many bytes. Here is one stored URL before a careless replacement, after it, and after a correct one:
Original: s:19:"https://old.example";
Malformed: s:19:"https://new-site.example";
Correct: s:24:"https://new-site.example";
The middle line promises 19 bytes and supplies 24. On PHP 8.3 and later, unserialize() returns false and raises an E_WARNING for input like that, and a plugin or theme that can’t read the saved value may fall back to defaults. That is how you can get widgets that vanished, a theme that forgot its colours, or a builder layout reset to empty after a domain change.
A serialization-aware tool such as WP-CLI unserializes the value, replaces inside it and serializes it again with the right length. The WordPress migration handbook recommends this kind of tool for domain changes.
One tempting shortcut is choosing a new domain with the same byte length so the lengths still match. That removes one way to break the data, but it doesn’t check the field or the application reading it, so I wouldn’t build a process on it.
Leave the GUIDs alone
Post guid values identify posts across moves, including to feed readers, and the handbook says to preserve them even when they contain the old hostname. An old domain left in the guid column is correct, so don’t read it as a missed replacement. That is why every replacement command below carries --skip-columns=guid.
How do you move the database safely with WP-CLI?
Export the live database, import it into a pre-created scratch database attached to a copy of the site, dry-run the replacement, read the report, then apply it on the copy only.

This also answers how to run WP-CLI search-replace on a MySQL dump: you don’t run it on the file. You import the dump into a scratch database that a WordPress copy’s wp-config.php points to, and run the command against that. Paths below are placeholders, the sample assumes a dedicated database for the source site, and you copy the matching files and uploads to the scratch path as well. wp db export needs mysqldump or mariadb-dump.
wp cli version
wp --path=/srv/source db export /srv/private/before-move.sql
wp --path=/srv/scratch db import /srv/private/before-move.sql
wp --path=/srv/scratch db tables --all-tables-with-prefix
wp --path=/srv/scratch search-replace 'https://old.example' 'https://new-site.example' \
--skip-columns=guid --dry-run
Stop if the export or import fails. Read the dry-run report table by table. Look for hits where you expect the exact old URL, such as the options table. If a plugin you know stores that URL shows none, find out why before moving on, because a zero-match report says nothing about skipped tables, config files or external services.
When the report looks right, apply the same scope and export the result:
wp --path=/srv/scratch search-replace 'https://old.example' 'https://new-site.example' \
--skip-columns=guid
wp --path=/srv/scratch db export /srv/private/moved.sql
What that command does and doesn’t reach, from the search-replace reference:
- It handles PHP serialization and preserves primary-key values. It skips tables without primary keys.
- The default scope is tables registered with
$wpdb.--all-tables-with-prefixadds unregistered tables with your prefix, and--all-tablesreaches other prefixes in the same database, which is a bad default on a shared database. - The sample targets one scheme and hostname. If the dry run or a later search shows
http://orwwwvariants, run separate passes for them.
If you’d rather get transformed SQL without writing to the scratch database, run this on the untouched copy in place of the apply and second export:
wp --path=/srv/scratch search-replace 'https://old.example' 'https://new-site.example' \
--skip-columns=guid --export=/srv/private/transformed.sql
Check which tables the export covers before you restore from it, and don’t treat it as your only backup. Our post on the 3-2-1 rule applied to real sites covers proving that a backup restores.
WP-CLI 3.0.0 came out on 1 December 2026, and its release notes list changes that touch this job: one detection scan per table, automatic matching of JSON-escaped URLs for literal replacements, and a database import fallback when no MySQL or MariaDB client exists. That fallback reads the whole file into memory, so keep the native client installed for large dumps. Run wp cli version first, because automatic matching of escaped slashes in literal URLs was added in 3.0.0.
The dashboard route exists too. Better Search Replace 1.4.11 offers table selection, serialized-data support and a dry run under Tools, and needs WordPress 6.2 and PHP 8.1 or newer according to its plugin page. I’d only use it when you can’t get shell access.
How do you rehearse a move on a large or busy database?
Time the full sequence on a recent copy, audit which tables get touched, and decide before cutover day how writes made after the copy will reach the new site.
I can’t give you a runtime or a size cutoff, and nobody else can honestly either: it depends on your tables, your serialized data and your server. Run the whole rehearsal, export, import, dry run and apply, with a stopwatch and write the numbers down. That tells you whether a short write freeze is enough or whether you need a final sync.
- Inventory first. List tables with
wp db tables --all-tables-with-prefixand look at their sizes. Our post on database bloat from revisions, transients and autoloaded options helps you see what is inflating the work. - Scope the pass. Use the default scope, or name reviewed tables as arguments on both the dry run and the real run. To include unregistered plugin tables with your prefix, use
--all-tables-with-prefixwith your reviewed table list on both runs. Skip--all-tableson a database shared with another app. - Use
--preciseselectively. By default the command runs SQL and switches to PHP for detected serialized data.--preciseforces PHP for every column and costs more time, and--logadds noticeable overhead too. Neither repairs data that is already malformed. - Check the variants. After the run, search the copy for
http://old.example,//old.exampleand the www form. - Plan the writes. Orders, accounts, comments and form submissions that reach the old site after your copy won’t be on the rehearsal. Freeze writes while you take and migrate a fresh copy, or sync the writes made since your copy before cutover. Our post on staging, version control and deploys for WordPress teams goes into the same gap.
After this you have a measured runtime and a written plan for new data, which turns the cutover into a decision instead of a hope.
Does the move involve a subdomain or a Multisite network?
Moving a standalone site to a subdomain is still a plain URL change, but a Multisite network needs more than the single-site recipe above.
To create a subdomain in WordPress on your own hosting, point DNS for the subdomain at the right server, configure the host to serve it and provision TLS. On WordPress.com you add the full hostname under Domains, and with external DNS you add the records the dashboard shows, as the subdomain guide describes.
| Setup | Address looks like | What to plan |
|---|---|---|
| Standalone site moving to a subdomain | shop.example.com | DNS, TLS, then the same rewrite as above. |
| Multisite, domain-based | shop.example.com | DNS and server routing for each site. Wildcard subdomains are needed when users can create sites on demand. |
| Multisite, path-based | example.com/shop | No DNS per site, but rewrite rules and every per-site address need review. |
For the WordPress Multisite subdirectory vs subdomain choice, pick path-based if you want one hostname and little DNS work, and domain-based if each site needs its own address and you control DNS and hosting. The network preparation handbook covers both, and the questions to answer before committing to Multisite covers the wider decision.
Moving an existing network is its own job. The handbook’s Multisite section asks you to review the network’s site and blogs tables and per-site options such as home, siteurl and fileupload_url where applicable. Switching between domain-based and path-based also touches SUBDOMAIN_INSTALL and rewrites, and table prefixes may not be wp_. A network-wide replace is not a finished Multisite migration, so rehearse it separately.
What should you verify before and after the DNS cutover?
Check that you can log in, that media loads from the new host, that plugin and theme settings survived and that old URLs redirect, all before real traffic arrives.
Run this on the rehearsal copy first and again right after cutover:
- Admin login works and cookies are set for the new host.
- Both the public address and the WordPress application address load on the restored site.
- Images, PDFs and fonts load from the intended host.
- Widgets, menus, theme options and page builder layouts look as they did. These settings can depend on serialized data, so look here hardest. On a CanvasWP site, include edited demo pages, header menus and Canvas blocks with media links.
- Forms send and a test order completes.
- A database search for the old hostname returns only places you expect, such as GUIDs.
- Any page, object and CDN caches in use are flushed. If the moved site still shows an old link, one of the caching layers may be serving a stale copy.
For search, Google recommends direct server-side permanent redirects such as 301 or 308 from each old URL to its new equivalent, updated canonicals and sitemap URLs, and keeping redirects generally for at least a year. For a move between domains or subdomains it also offers the Change of Address tool in Search Console, which it excludes for HTTP-to-HTTPS changes, switches between www and non-www on the same domain, and path changes within one domain. Nobody can promise a ranking outcome after a move. Our post on doing 301s without breaking rankings covers the redirect mechanics.
When to restore instead of patching
If serialized data is broken after the change, restore the affected data from the clean backup taken before the rewrite and rerun the replacement on a copy. Hand-editing lengths in a live database is easy to get wrong. If traffic has already moved, preserve the orders, comments and entries that arrived since, including their related data, then restore and reapply those writes. Chase leftover old references field by field, since a GUID may validly keep the old host.
Your first step
Take a fresh export of the site today, import it into a scratch database and run the dry run from this post with a stopwatch on. You will have a table-by-table report of what would change, a measured runtime for the dry run and a table inventory to check for plugin tables outside the replacement scope. Everything after that is a decision with real numbers behind it.
Frequently Asked Questions
How do I migrate a WordPress site to a new domain?
Back up the database and files, restore them to an isolated copy, dry-run a serialization-aware URL replacement and apply it there. Then verify the copy and map old URLs to new ones before you change DNS.
How do I move a WordPress site to a new domain when I also change hosts?
Copy the files and database, set the new database credentials in wp-config.php and check both the public and application URLs on the restored site. Rehearse on a clone and plan how any writes since the rehearsal reach the final site.
Why does WordPress search-replace break serialized data?
Serialized strings carry their byte length, so a plain replacement that changes the text length leaves a wrong number behind and PHP can’t unserialize the value. WP-CLI rewrites the value with valid lengths.
Can I run WP-CLI search-replace on a MySQL dump?
Not on the file itself. Import the dump into a pre-created scratch database used by a WordPress copy, then run the command there. You can also use --export=FILE to write transformed SQL for the selected tables.
What can I do if serialized PHP data breaks after a domain change?
Restore the affected data from the pre-change backup and rerun the replacement on a copy. If new orders or comments arrived since, save them separately first and reapply them after the restore.
How do I add a domain I own to WordPress?
On a supported WordPress.com plan, open Domains for the site, choose “Use a domain name I own” and follow the connection setup before making it the primary address. On self-hosted WordPress, add the hostname at your host and DNS provider, and use the migration steps if it replaces the public URL.
How do I transfer a domain from Squarespace to WordPress?
Check eligibility, turn off the domain lock at Squarespace and enter its authorization code in the WordPress.com transfer flow. That moves the registration only, so the website content has to be migrated separately.

