Skip to main content

Changing a WordPress Domain: Replacing URLs in DB

WordPress · 29.09.2026

Simply changing the address in WordPress settings does not move a site to a new domain: the old URL stays in thousands of database records, including serialized settings arrays used by page builders. Here is the right order for changing a domain without breaking the layout.

Why you cannot just change the address in settings

The site address is not stored only in the two fields siteurl and home in the wp_options table. Links to the old domain are scattered across post content, meta fields, menu and widget settings, and some plugins and page builders like Elementor store settings as serialized PHP arrays. If the domain inside them is replaced with a plain text search-and-replace, the string length in the serialized data no longer matches the real one, and PHP fails to parse the array — blocks on the page stop rendering.

Preparation: backup and estimating the scope of changes

Before making any database changes, take a full backup of the files and the database — the process is described in the article WordPress backup: UpdraftPlus and the manual method. Then count how many records contain the old address:

# Count how many times the old domain appears in the database
wp db query "SELECT COUNT(*) FROM wp_options WHERE option_value LIKE '%old-domain.com%'"

If the result is greater than zero in even one table, a plain SQL UPDATE query is risky — you need a tool that can handle serialized data.

Replacing the URL through WP-CLI: the safe way

The wp search-replace command can find and correctly recalculate string lengths inside serialized arrays — that is the main difference from a plain SQL query:

# First check the list of changes without writing to the database (dry run)
wp search-replace 'old-domain.com' 'new-domain.com' --dry-run

# Run the replacement across all tables, including multisite
wp search-replace 'old-domain.com' 'new-domain.com' --all-tables

The --dry-run flag shows the number of affected rows in each table without actually writing anything — always check the numbers before the real run. The full list of similar WP-CLI database commands is in the article WP-CLI Commands: Search-Replace in the Database and Creating an Admin.

What to check after the domain replacement

After running search-replace, go through these checkpoints:

What to checkWhere to look
Images and files in postsOpen 3-4 old posts and check that images load
Elementor and other page builder settingsOpen the page in the builder's editor, not just on the front end
Menus and widgets"Appearance → Menus" section, check menu items manually
PermalinksSettings → Permalinks → Save Changes

If some blocks on pages disappear entirely after the replacement, rather than just pointing to the old address, the replacement likely ran through a plain SQL query instead of search-replace and corrupted the serialization; restore the database from the backup and repeat the WP-CLI step.

Setting up redirects from the old domain

Even after fully replacing the address in the database, keep the old domain in DNS for a while and set up a 301 redirect on it to the new address — this preserves search rankings and keeps visits from old links on external sites from being lost. The rule is added to the old site's .htaccess:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^old-domain\.com$ [NC]
RewriteRule ^(.*)$ https://new-domain.com/$1 [R=301,L]

Keep the redirect active for at least 3-6 months, until search engines re-index the links to the new domain.

WordPress domain change checklist

  • A full backup of files and the database is made before starting the work.
  • The URL replacement is done with the wp search-replace command, not a direct SQL query.
  • Images, page builders, menus, and widgets are checked.
  • Permalinks are re-saved in the WordPress settings.
  • A 301 redirect to the new address is set up on the old domain.
← Back to Knowledge Base Ask Support