// blog / migrations

How I change a WordPress site's domain and keep its search history

To change a WordPress site's domain and keep its search history, I move the site, run a serialized search and replace so no old domain is left in the database, and 301 every old URL to the same path on the new domain. Then I tell Search Console and keep the old domain renewed.

By Muhammad Younus Updated 10 min read Migrations

Migrations and redesigns, SEO side: illustration for "Changing a WordPress domain, the SEO side"
// 01 - the risk

What changes for Google when a WordPress site changes domain?

Everything Google knows about your site is filed under its hostname. The pages, the links from other sites, the record of which URL answered which search: all of it points at the old domain. When you're moving a WordPress site to a new domain, Google sees a new site turn up with content it's already seen somewhere else. The only thing joining the two is a trail of redirects, and building that trail is the core of my website migration SEO services.

Can you change the domain of an existing WordPress website? Yes, and the content, design and plugins come with it. This post is for self-hosted WordPress; on a WordPress.com plan, you register or connect the new name and make it the site's primary address in its domain settings. I don't build or redesign sites. I do the search side and the database work that decides it.

Google files a domain change under site moves with URL changes: server-side permanent redirects, updated internal links and canonicals, and a new sitemap. It also warns that rankings may fluctuate while it recrawls and reindexes the site. Nobody can switch that off, and I won't put a date on it. What I control is whether every old URL tells Google where it went.

// 02 - the trap

Why can't I just edit the Site Address in Settings?

Because changing the WordPress site URL in that field changes two rows in the database and nothing else. Settings, General holds the WordPress Address and the Site Address, stored as the siteurl and home options. Change them and WordPress builds its own links from the new domain, but it doesn't move files or DNS, and it doesn't touch the places the old domain is written into content.

WordPress's own migration notes say that after changing the URLs in Settings, General you should expect to see a 404 page, and they carry a whole section on recovering from a site URL changed by accident.

Where the old domain hides in a WordPress database, and what I do with each
Where it's storedWhat it holdsWhat I do
siteurl and home in wp_optionsThe two addresses from Settings, GeneralChange them as part of the full replace, or set them in wp-config.php during the move
Post and page contentLinks and image URLs typed into the editorReplace old with new across every post, page and revision
Serialized options and widgetsTheme settings, widget text and plugin options stored with a length countUse a tool that reads serialized data, so the counts get rewritten too
Page builder data in post metaLayouts that carry full URLs for images, buttons and linksRun the builder's own replace as well, if it has one
The guid column in wp_postsA permanent ID for each post, used by feed readersLeave it alone. WordPress says never to change it

The serialized row is the one that bites. Some themes and widgets store a value with its length written in front of it. A plain SQL REPLACE swaps the domain but leaves the old count, and when the new domain is a different length, PHP can't read the value back. The widget empties, often with no error. WP-CLI's search-replace command handles serialized data properly, which is why it's the tool I use.

If WP-CLI isn't available: phpMyAdmin. WordPress's migration notes walk through editing the siteurl and home rows of wp_options in phpMyAdmin, and that's fine for those two rows. It isn't a way to change the domain in the database everywhere else, because the serialized values still need a tool that rewrites their counts. On hosts without WP-CLI, I run a search and replace plugin that handles serialized data, on a staging copy first.

// 03 - the method

How I change a WordPress site's domain, step by step

Most answers to how to change a domain name in WordPress stop at the database. My list runs on to the redirects and Search Console. The first four steps happen before anything goes live, and the Change of Address waits until the redirects pass.

  1. Step 01

    Back up, then pull the full URL list

    A full backup of files and database, then a list of old URLs from a crawl, the XML sitemap, the Search Console Performance export by page and a backlink export. The redirects get tested against that list later.

  2. Step 02

    Verify the new domain in Search Console

    I add the new domain as a Domain property verified with a DNS record before it carries any pages. Google's help says the DNS record has to stay in place for the property to stay verified.

  3. Step 03

    Put a copy of the site on the new domain

    If the host is changing, files and database move first. The old domain keeps serving the live site until the switch.

  4. Step 04

    Run the search and replace, dry run first

    wp search-replace 'https://old.example' 'https://new.example' --skip-columns=guid --dry-run reports every table and row it would change without saving anything. When the counts look right, I run it for real, then again for the http and www forms of the old domain.

  5. Step 05

    Replace inside the page builder too

    Elementor ships a wp elementor replace-urls command for its own data, and other builders need their own tool or a check by hand. Then every cache layer gets cleared: plugin, host and CDN.

  6. Step 06

    Check what lives outside WordPress

    The CDN zone, the SSL certificate on the new domain, SMTP settings, and any URL hardcoded in wp-config.php or a child theme.

  7. Step 07

    Switch on the redirects at server level

    One rule on the old domain sends every path to the same path on the new one with a 301 rather than a 302. On Apache: RewriteCond %{HTTP_HOST} ^(www\.)?old\.example$ [NC] and RewriteRule ^ https://new.example%{REQUEST_URI} [R=301,L]. On Nginx, a server block for the old names with return 301 https://new.example$request_uri;. A plugin can't do this, because WordPress no longer answers for the old domain.

  8. Step 08

    Test the whole URL list against the old domain

    Every URL from step one should answer with one 301 and land on a page returning 200. Anything that chains, loops, 404s or lands on the homepage gets fixed before Search Console hears about the move.

  9. Step 09

    Tell Search Console, then submit the new sitemap

    Only after the redirects pass. The Change of Address tool runs its own checks, and the new sitemap goes into the new property the same day.

// watch out

Never run a plain SQL REPLACE over the whole database, and never let any tool rewrite the guid column. A GUID is an ID, not a link, so one that still names the old domain is correct.

Rather have me do this? One person, whole job.

Book a call on Upwork
// 04 - the redirects

How do the redirects need to be set up for a domain move?

Path for path, at server level, in one hop. A domain change is the simplest redirect map there is, because WordPress keeps the paths. /services/roof-repair/ on the old domain becomes /services/roof-repair/ on the new one, so one pattern rule covers the whole site.

The usual mistake is sending everything to the new homepage. It throws the history away, because a homepage doesn't answer the searches the inner pages did. In one of my case studies, a WooCommerce catalogue's new URLs shipped without redirects and daily clicks fell from 162 to 49 in three days. That wasn't a domain change, but the cause was the same: old addresses that didn't lead to their replacement.

Every version of the old address, and where it should land
RequestAnswerWhy
https://old.example/page/301 to https://new.example/page/The main rule: same path, new host
http://old.example/page/301 to https://new.example/page/One hop, not an http to https hop on the old domain first
http://www.old.example/page/301 to https://new.example/page/The www form has links and history of its own
https://www.old.example/page/301 to https://new.example/page/Same rule, same destination
https://old.example/page/?ref=x301 to https://new.example/page/?ref=xQuery strings come across, so tracked links still work

Google counts 301 and 308 as permanent and prefers them server-side, not a JavaScript hop or a meta refresh. Wherever the rule lives, I check the real status code with a header request, because the setting and the response don't always agree.

// 05 - search console

What do I tell Search Console, and when?

Search Console hears about a domain change in four stages, and each one waits for the stage before it.

  1. i.

    Before the move: both properties verified

    The Change of Address tool needs the same Google account to own the old and the new property, and the old property has to sit at domain level, with no folder in its address.

  2. ii.

    After the redirects pass: the Change of Address

    It's filed from the old property, only for a move from one domain or subdomain to another, and Google keeps the forwarding signal for 180 days. Subdomains don't move with it, so a shop subdomain gets its own request.

  3. iii.

    Same day: the new sitemap

    The new domain's sitemap goes into the new property, and it should list only new URLs that return 200. If a plugin still prints old domain URLs into it, the sitemap and robots.txt get fixed before it's submitted.

  4. iv.

    The weeks after: the Pages report on both sides

    On the old property, URLs moving to Page with redirect is the healthy sign. On the new one, pages stuck at Discovered, currently not indexed for weeks have a diagnosis of their own.

// pro tip

The Change of Address tool isn't for an http to https switch, a www change or a new folder on the same domain. Those only need the redirects and an updated sitemap.

// 06 - the old domain

How long should the old domain stay registered?

Longer than Google asks, and I'd say for good. Google's site move guide says to keep the redirects as long as possible, generally at least a year. The Change of Address help asks for at least 180 days and recommends paying for the old domain for at least a year, so nobody else can buy it and use it for something malicious.

Links from other sites don't update themselves because you moved. An old directory listing or forum thread points at the old domain for as long as it exists, and every click on it needs the redirect.

Email is the other reason. If inboxes or old invoices still use the old domain, its MX records have to keep working until every one has moved. Letting it lapse loses the redirects and the mail in one go.

// when to hand this over

If you're changing a WordPress site's domain and you'd like one person to own the search side, from the URL list and the replace to the redirects, Search Console and the weeks after, that's the migration work I do. Your host and your developer keep their parts.

Book a call on Upwork

Is this your site? Send me the URL.

Book a call on Upwork
// questions - migrations

What else do people ask about this?

How do I transfer my WordPress site to a new domain?

Copy the site to the new domain, run a serialized search and replace in the database, 301 every old URL to the same path, then file a Change of Address in Search Console once the redirects pass.

Why is the WordPress Address (URL) field greyed out?

Because the address is set in wp-config.php with WP_HOME and WP_SITEURL. WordPress's migration notes say you won't be able to edit them on the General settings page while those lines are there, so change them in wp-config.php.

Will changing my domain hurt my rankings?

It can wobble for a while. Google warns that rankings may fluctuate while it recrawls and reindexes a moved site. What I can test is every old URL reaching its new address in one hop.

Should I change the GUIDs when I change domain?

No. WordPress's migration notes say never to change the GUID column, under any circumstances. It's a permanent ID that feed readers rely on, so a GUID naming the old domain is exactly right.

Can I let the old domain expire after a year?

I wouldn't. A year is the minimum Google suggests paying for it, and links from other sites keep pointing at the old address long after that.

// sources - checked

Where do these rules come from?

Platform and Google documentation, opened and read on the day this was written. Everything else is how I work.

  1. Google Search Central: site moves with URL changes
  2. Search Console Help: Change of Address tool
  3. Search Console Help: verify your site ownership
  4. WordPress Advanced Administration: migrating WordPress
  5. WordPress.org documentation: Settings General screen
  6. WP-CLI command reference: wp search-replace
  7. Elementor Developers: replace-urls CLI command
  8. WordPress.com Support: change a WordPress.com domain name address
  9. Apache HTTP Server 2.4: redirecting and remapping with mod_rewrite
  10. nginx documentation: ngx_http_rewrite_module, the return directive
Muhammad Younus, WordPress technical SEO consultant
// who wrote this

One consultant, writing down his own method

I'm Muhammad Younus, a WordPress technical SEO consultant with 8+ years of experience and 100+ client sites fixed. Top Rated Plus on Upwork with a 100% Job Success Score. Every post here is the way I actually do the job, written in the first person because it's one person doing it, remotely, with no team behind the name.

Nothing in these posts is a client I can't name or a number I can't show. Where a figure comes from a client's Search Console, it's from a published case study, and where a rule comes from Google or a platform, the source is linked at the bottom of the post.

// the service behind this post
Muhammad Younus smiling and giving a thumbs up
// next step

Want this done on your own site?

Book a call on Upwork, send the URL and read-only Search Console access, and you'll get a written scope for the search side before any work starts. One person does the whole job, remotely.

Book a call on Upwork