Skip to content

Migrate WordPress without losing search rankings: the operator runbook

What actually causes ranking loss at a WordPress migration, and the runbook that prevents it: a baseline crawl, a tested one-to-one 301 map, the right cutover sequence for host, domain, HTTPS and permalink changes, and a 14-day validation window.

Sites almost never lose rankings because they moved. They lose rankings because their URLs, their crawlability, or their response headers changed during the move and nobody noticed for three weeks. The fix, in short: crawl the live site before you touch anything, so you know which URLs exist and which ones earn clicks; build a one-to-one 301 map with no intermediate hops; make sure the staging site’s noindex flag and its robots.txt never travel to production; keep the old host answering redirects for months, not days; then watch index coverage, the 404 reasons, and your access log for two solid weeks. Skip the baseline crawl and you are debugging blind, with no record of what used to work.

What you’ll accomplish

  • Produce a baseline you can diff against: every URL, its status code, and the pages that earn clicks.
  • Build and verify a redirect map where every legacy URL resolves in exactly one hop.
  • Pick the right procedure — host change, domain change, HTTPS change, and permalink change are four different jobs.
  • Sequence the cutover so DNS, redirects, sitemaps, and Search Console filings do not strand Googlebot.
  • Run a 14-day validation window, and tell normal noise apart from a real regression.

Prerequisites

  • Search Console verified on the origin property and the destination property before cutover day. On a domain change, verify the new one weeks ahead.
  • Shell access to both hosts, with WP-CLI. Written against WordPress 6.8, WP-CLI 2.11, PHP 8.2/8.3, on Apache 2.4 or nginx 1.24+.
  • The ability to edit web-server config directly. A redirect plugin is a fallback, not the plan.
  • An analytics baseline of at least 90 days, plus a Search Console Performance export (Pages tab, last 3 months, clicks descending). Neither can be reconstructed after the move.
  • DNS control at the registrar or authoritative provider, including the ability to lower TTLs.
  • Assumed: a single-site install with a public sitemap, either core’s /wp-sitemap.xml or an SEO plugin’s /sitemap_index.xml.
  • The pre-migration inventory guide covers the infrastructure stocktake this article assumes is already done.

How it works

Search engines hold a URL-keyed map of your site: every ranking, every accumulated link signal, every crawl-scheduling decision hangs off a specific URL string. A migration is dangerous exactly to the degree that it rewrites those strings or changes what they return. That gives a short list of real causes, each with its own fix:

  • URL changes with no redirect. The old URL 404s and every signal attached to it is orphaned. Largest single cause of migration ranking loss.
  • Redirect chains. /old-a sends to /old-b sends to /new. It resolves, but each hop adds latency and long chains get truncated before the destination.
  • noindex carried over from staging. The “Discourage search engines” checkbox writes blog_public = 0, emitting a site-wide noindex. Clone staging to production without clearing it and you deindex yourself.
  • robots.txt holding Disallow: / from the staging host. This blocks crawling rather than indexing, so Google never sees the redirects you built.
  • Canonical or hreflang pointing at the old host. Absolute URLs baked into the database keep declaring the old address authoritative.
  • Lost internal links. Hard-coded absolute links in post content now travel through a redirect, or die outright.
  • Slower TTFB. Crawl budget follows response speed; a site that got slower gets crawled less.
  • Dropped Last-Modified headers. Conditional requests stop working and the crawler loses a freshness signal.
  • A stale sitemap. It advertises addresses that now redirect, which is a slow way to get recrawled.

The runbook below closes each of those, in an order where every stage produces a written artifact the next stage depends on.

Five-stage migration timeline running from a baseline crawl fourteen days out, through the redirect map, DNS TTL lowering and staging-flag cleanup, the cutover itself, and a fourteen-day validation window, with the specific SEO artifact each stage must produce shown beside it

First, decide which of four jobs you are actually doing, because the risk is not equal:

  1. Host change only — same domain, same URLs, lowest risk. No redirect map. The exposure is DNS, TTFB, and staging flags.
  2. HTTPS change — every URL technically changes. Needs a site-wide 301 and a canonical update, but not the Change of Address tool, which does not handle protocol moves.
  3. Domain change — needs a full 301 map, both properties verified, and the Search Console Change of address tool on the old property.
  4. Permalink structure change — highest per-URL risk, because the mapping is generated rather than mechanical. It is also the only one you can choose not to do; if it was bundled into a host move for tidiness, ship it separately a month later.

Google’s site move with URL changes documentation is the reference for cases 2 through 4.

Step-by-step

1. Crawl the live site and freeze the baseline. Run this from outside, against production, before anything changes.

wget --spider --recursive --level=inf --no-verbose --no-parent \
     --output-file=crawl-baseline.log https://example.com/
grep -oE 'URL:[^ ]+' crawl-baseline.log | sed 's|^URL:||' | sort -u > old-urls.txt
wc -l < old-urls.txt
4812

A crawl only finds what is linked, so cross-check against the database:

wp post list --post_type=any --post_status=publish --field=url | sort -u >> old-urls.txt
wp term list category --field=url >> old-urls.txt
sort -u -o old-urls.txt old-urls.txt
wc -l < old-urls.txt
4907

The gap is your orphan set — published URLs nothing links to. They still rank, so they still need redirects.

2. Record the status code of every baseline URL. This is the artifact you diff against after cutover.

while read -r u; do
  printf '%s %s\n' "$(curl -o /dev/null -s -w '%{http_code}' "$u")" "$u"
done < old-urls.txt > baseline-status.txt
awk '{print $1}' baseline-status.txt | sort | uniq -c | sort -rn
4871 200
  30 301
   6 404

Note the pre-existing 404s so you do not blame them on the migration later.

3. Export the pages that actually matter. In Search Console, open Performance → Search results, set the range to the last 3 months, switch to the Pages tab, sort by clicks, and export. Keep the top 200 as priority-urls.txt — those get hand-verified on cutover day.

4. Decide, per URL, what happens to it. Every entry in old-urls.txt gets one of three outcomes, and the decision is mechanical once stated plainly.

Decision tree taking a legacy URL from the inventory through two questions — whether the address changes, and whether the old address must keep serving its own content — to one of three outcomes: no action, a one-to-one 301, or a rel=canonical; below it a contrast between a two-hop redirect chain and a single direct 301

Write the result as a two-column tab-separated file. Everything else generates from it:

head -3 redirects.tsv
/old/product-a/	/products/product-a/
/2019/07/hello-world/	/blog/hello-world/
/shop/item-42	/products/item-42/

5. Generate the server config from the map. On Apache, RedirectMatch with anchors gives exact matches instead of Redirect’s prefix behaviour, which is the usual source of surprise redirects:

awk -F'\t' 'NF==2 {printf "RedirectMatch 301 ^%s$ %s\n", $1, $2}' redirects.tsv > redirects.conf
wc -l < redirects.conf
1284

Include that above WordPress’s own rewrite block in .htaccess, or better, in the vhost. On nginx, use a map plus one lookup in the server block — it stays fast at thousands of entries where stacked rewrite rules do not:

map $request_uri $legacy_target {
    default "";
    /old/product-a/         /products/product-a/;
    /2019/07/hello-world/   /blog/hello-world/;
}

server {
    if ($legacy_target) { return 301 $legacy_target; }
}

Use a redirect plugin only when you have no server access. Plugin redirects run after WordPress boots, so they cost a full PHP request per hop and stop working the moment the plugin is disabled.

6. Rewrite the database with a dry run first. Never run a live search-replace without seeing the count:

wp search-replace 'https://old.example.com' 'https://example.com' \
  --all-tables --dry-run --report-changed-only --skip-columns=guid
+---------------+-----------------------+--------------+------+
| Table         | Column                | Replacements | Type |
+---------------+-----------------------+--------------+------+
| wp_options    | option_value          | 41           | PHP  |
| wp_postmeta   | meta_value            | 2109         | PHP  |
| wp_posts      | post_content          | 8873         | SQL  |
+---------------+-----------------------+--------------+------+
Success: 11023 replacements to be made.

--skip-columns=guid is not optional: GUIDs are permanent identifiers, not URLs, and rewriting them makes feed readers re-deliver your whole archive as new. The WP-CLI search-replace reference covers serialized-data handling. Drop --dry-run once the counts look sane, then flush:

wp search-replace 'https://old.example.com' 'https://example.com' \
  --all-tables --report-changed-only --skip-columns=guid
wp rewrite flush --hard
wp cache flush

7. Clear the staging flags before anything goes public. These two checks catch the most expensive mistakes in this article.

wp option get blog_public
curl -s https://new-host.example.com/robots.txt
1
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Sitemap: https://example.com/wp-sitemap.xml

blog_public must be 1; if it returns 0, fix it with wp option update blog_public 1. If robots.txt contains Disallow: /, find out whether it is a physical file left by the staging host or plugin output — deleting the file will not help in the second case. Then confirm no header-level block survived:

curl -sI https://new-host.example.com/ | grep -i 'x-robots-tag'

Empty output is the success signal. A line reading X-Robots-Tag: noindex means the block lives in the web server or a security plugin, not in WordPress settings.

8. Lower DNS TTL two days ahead. Set the A/AAAA records to 300 seconds well before the window, so both the cutover and a rollback are quick.

dig +noall +answer example.com A
example.com.		300	IN	A	203.0.113.10

If that number still reads 3600, wait out the old TTL. Resolvers holding the old record make the cutover window fuzzy rather than instant, so plan for both hosts to serve traffic at once for a while.

9. Cut over, then verify redirects end to end. Flip DNS and immediately test the priority list. The -L flag follows the chain so you can count hops:

curl -sI -o /dev/null -L -w '%{num_redirects} %{http_code} %{url_effective}\n' \
  https://example.com/old/product-a/
1 200 https://example.com/products/product-a/

One redirect, ending in 200, at the address you intended. Run the whole map and print only rows that fail that shape:

while IFS=$'\t' read -r old new; do
  printf '%s\t%s\n' "$old" \
    "$(curl -sI -o /dev/null -L -w '%{num_redirects} %{http_code} %{url_effective}' "https://example.com$old")"
done < redirects.tsv | awk -F'\t' '$2 !~ /^1 200 /'

No output means every mapped URL resolves in one hop with a 200. Any printed line is a chain, a loop, or a wrong destination; the redirect chain audit with curl guide goes deeper on reading these traces.

10. Regenerate and resubmit the sitemap. A sitemap full of redirecting URLs slows rediscovery.

curl -sI https://example.com/wp-sitemap.xml | head -1
curl -s https://example.com/wp-sitemap.xml | grep -c 'sitemap>'
HTTP/2 200
14

Submit the sitemap URL on the new property under Sitemaps. On a domain change, leave the old property’s sitemap in place too — Google needs to recrawl those old URLs to see the 301s.

11. File the Change of Address, if and only if the hostname changed. On the old property, go to Settings → Change of address, select the new property, and submit. Search Console checks that a sample of old URLs redirects to the new site, so run step 9 first or the filing is rejected. Do not use it for an HTTP-to-HTTPS move or a permalink change — neither is a site move in Google’s sense.

Validate it works

Day 0, within an hour of cutover: walk priority-urls.txt by hand with the curl one-liner from step 9 and confirm every entry lands in one hop. Spot-check five pages with URL Inspection’s “Test live URL” and confirm the crawled canonical is the new address.

Day 1: check how Googlebot is being served on the new host.

grep -i 'googlebot' /var/log/nginx/access.log | awk '{print $9}' | sort | uniq -c | sort -rn
   8421 200
    612 301
     18 404

A tail of 301s is expected: Google working through the legacy set. The 404s are the actionable number:

grep -i 'googlebot' /var/log/nginx/access.log \
  | awk '$9==404 {print $7}' | sort | uniq -c | sort -rn | head -20

Every URL there is a hole in your map: add it, reload, retest. Repeat daily for the first week — the long tail surfaces gradually, so a clean day 1 does not mean a clean day 7.

Days 2 through 14: in the Pages report on the new property, watch the “Not found (404)” and “Page with redirect” reasons — redirect counts should rise, then fall as Google consolidates. In Settings → Crawl stats, confirm average response time has not degraded; a slower host gets crawled less. Finally, diff every baseline URL against the day-0 snapshot:

while read -r code u; do
  now=$(curl -o /dev/null -s -L -w '%{http_code}' "$u")
  [ "$now" = "200" ] || printf '%s was:%s now:%s\n' "$u" "$code" "$now"
done < baseline-status.txt

The only lines that should print are the pre-existing 404s from step 2.

Set expectations honestly with whoever is watching the graphs. Some fluctuation is normal for one to four weeks even on a clean migration, and larger sites take longer. A dip in impressions during week one is not by itself evidence of a mistake; a dip still deepening at week four is. Rankings are never guaranteed to survive a move — a careful migration only ensures nothing structural works against you while Google re-settles. The post-migration smoke tests checklist covers the non-SEO half of day 0.

Troubleshooting

Redirect loop after cutover. curl reports curl: (47) Maximum (50) redirects followed. Almost always two rules fighting: a server rule pointing /old/ at /new/ while WordPress’s canonical redirect sends /new/ back because home or siteurl still holds the old value. Check wp option get home and wp option get siteurl, then look for an HTTPS-forcing rule running before your map.

Everything 200s but nothing is indexed. Read the response, not the settings screen: fetch a page and look for a robots meta tag or an X-Robots-Tag header carrying noindex. If blog_public is 1 and the header persists, the source is a security plugin, a CDN worker, or a leftover vhost directive.

Google is not crawling at all. Fetch robots.txt from the live domain, not from your notes. A Disallow: / copied from the staging host blocks crawling entirely, so Google never sees your redirects and the old URLs age out on their own schedule. Fix the file, then request recrawl of a few key pages through URL Inspection.

Redirects work but take two or three hops. This is what a domain change layered on an existing HTTPS redirect layered on a trailing-slash rule produces. Collapse them: every rule in the map should point at the final canonical URL — protocol and trailing slash included — so the first hop is the last hop.

Mixed content warnings after an HTTPS move. Absolute http:// URLs survived in post content, widgets, or serialized plugin options. Re-run wp search-replace with the protocol-only pattern and --dry-run to see what is left, and check wp_options — customizer settings hold serialized data that a naive SQL UPDATE would corrupt but WP-CLI handles correctly.

When this is the wrong approach

This runbook assumes you want to keep the URLs’ accumulated value, which is the normal case. It is the wrong shape of work in a few situations.

If you are deliberately retiring content — a pruning pass, a defunct product line — do not redirect those URLs to the homepage to avoid a 404. A redirect to something unrelated is treated as a soft 404 anyway, and it buries real problems inside a wall of successful-looking 301s. Let dead pages return 410 Gone, and reserve 301 for URLs with an actual equivalent.

If the site has a couple of hundred URLs and negligible organic traffic, the full apparatus costs more than it returns. Do the baseline crawl and the redirect map; skip the log-file analysis and the 14-day watch.

If the destination platform cannot express arbitrary redirect rules — some hosted builders allow only a fixed list — the map is not implementable, and the honest answer is to pick a different destination.

And if the migration is driven by a performance problem, measure first. A faster host helps crawl budget, but if the bottleneck is an uncached query or a plugin making remote calls on every request, the same page stays slow after the move.

Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.