Blog
WordPress Migration Without Losing Rankings or Data
A wordpress migration that keeps rankings and data: inventory the live URLs, back up files and the database, replace URLs safely, and then cut DNS over.
Muhammad Zubair Akhtar
A wordpress migration copies the files and the database to a new host, then points DNS at that host so the same URLs still resolve. Rankings are tied to those URLs. Data is the database plus the files it names, above all wp-content/uploads. A homepage that loads is not a finished move if either half is missing.
I am Zubair Akhtar (Muhammad Zubair Akhtar), a senior software engineer in Lahore, Pakistan. This is how I migrate wordpress site to new host when the address should stay: inventory, backups, plugin or manual copy, wp-config.php, URL replace, a hosts-file test, a shorter TTL, SSL, then cutover. On 9 November 2026 I read the migrating handbook (modified 14 October 2026), WP-CLI search-replace, db export, and db import (each modified 8 November 2026), plus Google on changing your hosting and Change of Address. I have not run these commands for this article.
The same sequence is WordPress development. A compromised tree copies the malware with it, so clean first using the WordPress hacked recovery playbook.
What a wordpress migration has to keep
The URL is the ranking
Google's hosting guide is the same-URL case: prepare the new host, change DNS, watch traffic, and shut the old host down only when it is idle. Change of Address is for a new domain or subdomain, not a host change that leaves the URL alone.
Keep the scheme, host, and path. https://example.com/pricing/ should stay that URL. Google says a domain move plus a new structure is when it may have to relearn pages, so change permalinks later, with redirects.
Both stores have to move
Posts, users, and home / siteurl are in MySQL. Themes, plugins, and uploads are on disk. Missing wp-content/uploads means image 404s. Missing the database means a theme and no content. To migrate wordpress database rows, import into a database the new wp-config.php can open, then see if any stored URL must change.
The handbook's URL steps are for one site. Multisite stores the domain in more tables, and wp search-replace needs --network or it edits only the current site. A network move is out of scope here.
Inventory before you touch DNS
Save the URL list
Save the sitemap, internal links, and one URL per template, with today's status code. Request that list again after cutover. A 200 that is now a 404 is a migration bug. Note permalinks, www versus the apex, and any HTTP to HTTPS redirect. Changing those at the same time means the URLs did not stay put.
Search Console, then backups
Google's hosting guide says an HTML verification file has to be in the new tree, and a theme meta tag has to move with the theme. A pages export is the before-list.
The handbook says to back up files and the database first. Keep that copy off the machine you are leaving: wp-content, wp-config.php, .htaccess on Apache, and a MySQL dump.
wp db export wp-backup.sql
mysqldump --single-transaction --no-tablespaces -u dbuser -p database_name > wp-backup.sql
wp db export runs mysqldump from the DB_* values in wp-config.php. The command page says it adds --no-tablespaces unless you pass --include-tablespaces. --single-transaction is an InnoDB snapshot. I have not run either line. Stop orders and new posts before the final dump, or a later checkout never lands in the file you import.
Plugin or a manual copy
| Method | What moves | When I use it |
|---|---|---|
| Plugin | Files and database in one package | No shell, or the host insists on its own tool. Keep a SQL dump too |
| Manual | rsync or scp, then wp db export / wp db import | SSH, a large uploads folder, or you want each step visible |
Read that plugin's limit and whether it rewrites URLs. I have not installed one for this page. Keep the SQL dump anyway, and skip cache directories and old zips in the web root.
Run rsync again for files that changed. Skip --delete on the first copy so you do not remove a certificate or a config that exists only on the new host:
rsync -a --exclude 'wp-content/cache' --exclude 'wp-content/upgrade' \
./ user@new-host:/var/www/html/
Create the empty database first. The wp db import page says the command does not create it, and that it only runs the SQL you give it, using wp-config.php.
wp db import wp-backup.sql
$table_prefix has to match the dump. Tables named wp_posts will not fill a prefix of wpxyz_.
Update wp-config.php
Set DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST when the database, its name, or its user changed. DB_HOST is localhost only when MySQL is on that machine.
WP_HOME and WP_SITEURL override the options of the same name. The handbook shows both with a scheme and no trailing slash:
define( 'WP_HOME', 'https://example.com' );
define( 'WP_SITEURL', 'https://example.com' );
Settings → General cannot edit those constants. On a same-domain move, leave them unset if the database already has the public URL, and remove a hard-coded staging host before DNS changes. Copy the salts to keep current logins. New salts sign people out. The handbook says to delete RELOCATE after using it, and that leaving it is insecure.
Replace URLs with wp search-replace
Skip this when the scheme, host, and path did not change. The handbook's same-URL move is files, the database, and the config.
Replace when the domain changes, when content still says http://, or when posts and options still contain a staging host. Updating home and siteurl does not rewrite post_content images or widget and plugin options.
Serialized lengths are why raw SQL fails
serialize() stores a string with its byte length:
s:19:"https://old.example";
https://old.example is 19 bytes. SQL REPLACE() or a text editor can lengthen the URL and leave s:19 in place. unserialize() fails. Widgets, menus, and plugin settings come back empty. The handbook warns about this because themes and widgets store that length.
The handbook's command is wp search-replace. Its docs say it handles serialized data, does not change primary keys, and skips tables with no primary key. SQL is used on ordinary columns and PHP on serialized ones. --precise forces PHP everywhere. --dry-run does not write.
Pass --skip-columns=guid. The handbook says the GUID identifies a post in feeds and that you should not change it. The command examples include the flag. I am not calling it the default.
wp search-replace 'https://old.example' 'https://example.com' --dry-run --skip-columns=guid
wp search-replace 'https://old.example' 'https://example.com' --skip-columns=guid
Read the dry run. Replace the full URL, scheme included, so you do not rewrite an email that only contains the domain. Run http:// and https:// separately if both are stored. Defaults are $wpdb tables. --all-tables-with-prefix adds other prefixed tables. --all-tables ignores the prefix. Multisite needs --network. Do this on the new copy.
Test with a hosts file
Google says to test first, by IP limit or a temporary hostname with noindex. A hosts file checks the public name on one computer and leaves everyone else on the old IP.
203.0.113.10 example.com www.example.com
Use the new server's address. 203.0.113.10 is a documentation example. The file is /etc/hosts on Linux and macOS, and C:\Windows\System32\drivers\etc\hosts on Windows. Open a page, an upload, wp-login.php, and a form. Check the certificate, permalinks, and home / siteurl, then delete the line so a rollback applies to you too.
Fix a staging URL, a missing upload, a plugin fatal, or a stale cache before DNS sends anyone else to this host.
TTL, SSL, and the cutover
TTL is how long a resolver may cache a record. Google's hosting guide says to lower it to a conservative value (their example is a few hours) at least a week before the move. Resolvers that already cached the old TTL keep it until that copy expires. Publish the short value, wait out the old one, then change A and AAAA. Raise the TTL after traffic has moved. I am not quoting a measured cutover.
Have a certificate for the public name before visitors arrive. Reuse the current cert and key if they still match. A DNS challenge can finish early, because the CA reads a TXT record. An HTTP challenge waits until the new host is reachable. nginx is in the nginx setup guide. On Apache, resave permalinks and put back custom redirects from .htaccess.
Stop writes, export, import, and repeat search-replace only if that dump brought the old URL back. Remove staging noindex and Disallow: /, then point DNS at the new address. Google describes old-server traffic falling as the new server picks it up. Check A and AAAA outside your hosts file, and keep the old host until its logs are idle.
Redirects only if the URL changes
Same path means no redirect map. A 301 of every URL to the homepage drops the address the ranking used.
A new path or domain needs one 301 from each old URL to the closest new one. Keep the structure when you can. List only the new canonicals in the sitemap, and point each canonical at production, not at the old host or staging. That check is the technical SEO checklist. HTTP to HTTPS, and www versus the apex, are redirects and canonicals. Google says not to file Change of Address for either.
Leave staging robots.txt and noindex behind
A temporary hostname should stay out of the index. Google says to send noindex on it, and to remove crawl blocks before the real move. Disallow: / stops the fetch, so HTML noindex is never read. That split is the robots.txt guide.
Before DNS changes, request the production name against the new IP. Robots.txt must be the live file, and the homepage must not send noindex. The temporary name can keep noindex until you delete it. The real domain must not.
Checks after DNS moves
Request the saved URL list again. Fix a new 404 at the cause, a missing file or unsaved permalinks, instead of sending it to the homepage. Confirm the canonical and resubmit the sitemap. Google says crawl rate can dip after a host change and then rise if the new host is not failing or slow. That is not a ranking promise.
Use Change of Address only for a new domain or subdomain, with the same account on both properties and the 301s already live. Google says to keep those redirects at least 180 days, longer if the old URLs still get traffic. A new PHP version or cache is the next job: WordPress speed optimization for page and object cache, and the WordPress security checklist for accounts, updates, and backups.
Rollback
Keep the old host and the pre-replace backup. Point DNS back and wait out the TTL if the new host is wrong. That restores the old site only. Later writes on the new host are not in the old database, and nothing merges them. If salts changed or the old database was rewritten, restore the backup pair.
Pre-flight and cutover checklist
Before DNS
- URL list saved with today's status codes
- Search Console verification is on the new copy
- Files and database backed up, off both servers
- Plugin or
rsync/scpchosen, plus a SQL dump - New database created;
DB_*and$table_prefixmatch the dump - Replace skipped, or
--dry-runand--skip-columns=guidreviewed - Hosts file checked: pages, uploads, login, form, certificate
- Production name does not send staging
noindexorDisallow: / - TTL lowered, and the previous TTL has elapsed
- Old host stays online
Cutover
- Old site is not taking writes
- Final export imported
- Search-replace repeated only if that dump brought the old URL back
- Production robots.txt, and no public
noindex - A and AAAA point at the new host
- Logs leave the old host and hit the new one
After
- Saved URLs requested again; new 404s fixed at the source
- Canonicals are production; sitemap resubmitted
- Change of Address only if the domain or subdomain changed
- Old host kept until its logs are idle
- Rollback is the old address plus the backup pair
FAQ
Will a new host hurt rankings if the URLs stay the same?
Google treats that as an infrastructure change. Keep the URL, serve a matching certificate, and do not leave staging noindex or Disallow: / on the public host. A crawl-rate dip is described in their hosting guide. It is not a promise about every query, and not a reason to change permalinks in the same window.
Can I find-and-replace the SQL file?
Not when the new URL has a different length. The serialized count stays wrong and unserialize() fails. Import, then wp search-replace --dry-run, and skip guid.
Does a same-domain host change use Change of Address?
No. Google reserves it for a new domain or subdomain, after the 301s, with one account on both properties. A host or CDN change, HTTP to HTTPS, and www versus the apex do not use it.
The hosts file worked and the public site did not.
Only your computer used the new IP. Check A and AAAA from another network, confirm the final dump was imported, and confirm staging robots rules are gone.
How do I roll back?
Point DNS at the old host and wait out the TTL. Restore the backup if that database was rewritten or the new host took writes you must drop. Two live databases do not merge.
Work with me
I do this as WordPress development: the copy, the database, the URL replace, and a check that production is not still marked staging. Spam users or odd files mean the recovery playbook comes before rsync.
Send the current URL, whether the domain changes, and which host has SSH. The URL list and the database lines in wp-config.php show whether the job is a copy or a rewrite.
