Before you start
- A fresh backup of the database
- The new domain already resolving to the server, with a valid certificate
- SSH with WP-CLI, or FTP access to wp-config.php
Step 1: Know the two settings
WordPress stores its address twice, in the options table: home (the Site Address, what visitors type) and siteurl (the WordPress Address, where its files live). For most sites they are identical. Write them without a trailing slash.
Step 2: Change them in the dashboard if you can
Settings → General. Saving logs you out, because your login cookie belongs to the old address; log in again at the new one. If the fields are greyed out, they are fixed in wp-config.php and must be changed there.
Step 3: Or change them from outside WordPress
If you are locked out, either define the addresses in wp-config.php or update the options with WP-CLI. Constants in wp-config.php override the database, so remove them later if you want the dashboard fields back.
define( 'WP_HOME', 'https://newdomain.com' ); define( 'WP_SITEURL', 'https://newdomain.com' ); # or wp option update home 'https://newdomain.com' wp option update siteurl 'https://newdomain.com'Step 4: Replace the old address in the content
Links and image URLs in posts, widgets and theme settings still use the old domain. Do not run a plain SQL REPLACE: WordPress stores some settings as serialised PHP, which records each string's length, and changing the text without the length corrupts them. WP-CLI's search-replace handles this. Skip the guid column — post GUIDs are identifiers and should not change.
wp search-replace 'https://olddomain.com' 'https://newdomain.com' --skip-columns=guid --dry-run wp search-replace 'https://olddomain.com' 'https://newdomain.com' --skip-columns=guidStep 5: Flush what is cached
Re-save Settings → Permalinks, then purge the page cache and any CDN. Cached pages still contain the old links.
Step 6: Redirect the old domain permanently
Keep the old domain pointing at the server and send every path to the same path on the new one with a 301. If the old domain was in Google Search Console, use its Change of Address tool as well.
RewriteEngine On RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC] RewriteRule ^(.*)$ https://newdomain.com/$1 [L,R=301]
The mistake people make
Running a find-and-replace in SQL or a text editor on the database dump. Serialised values whose length changed stop loading, and widgets, menus and theme settings silently reset to defaults.
