You might need to change your WordPress URL when you move to a new domain, switch from HTTP to HTTPS, move from a subfolder to the root, or bring a staging site live. WordPress stores its address in two settings, WordPress Address (siteurl) and Site Address (home), and also in thousands of links inside your content. Changing it properly takes three steps.
Before you start
- Back up the database and files. See WordPress backup without a plugin.
- Point the new domain’s DNS at your server, and get an SSL certificate for it. See point a domain to a VPS and Let’s Encrypt.
- Update the Nginx (or Apache) server block so the new domain serves the site. See Nginx server blocks.
Step 1: change siteurl and home
Choose one method.
A. In the dashboard (if you can log in): Settings → General → change WordPress Address (URL) and Site Address (URL) → Save. You’ll be logged out and redirected to the new address. That’s normal.
B. WP-CLI (recommended on a VPS):
cd /var/www/example.com
wp option update home 'https://new-example.com'
wp option update siteurl 'https://new-example.com'
C. wp-config.php (overrides the database values; useful if you’re locked out):
define( 'WP_HOME', 'https://new-example.com' );
define( 'WP_SITEURL', 'https://new-example.com' );
The settings fields are greyed out while these constants are defined. Either keep them, or remove them after fixing the database values.
D. SQL (if all else fails):
UPDATE wp_options SET option_value = 'https://new-example.com' WHERE option_name IN ('home','siteurl');
Step 2: replace old URLs in content
Posts, widgets, menus, page builder data and plugin settings still contain the old URL. Use a serialization-aware search-replace. A plain SQL REPLACE() breaks serialized PHP data:
wp search-replace 'https://old-example.com' 'https://new-example.com' --all-tables --precise --dry-run
wp search-replace 'https://old-example.com' 'https://new-example.com' --all-tables --precise
wp cache flush
Run the dry run first, and check the counts. Also replace protocol-less or http:// variants if your content has them. Details: WordPress search-replace in the database.
No shell access? Plugins such as Better Search Replace do the same from the dashboard.
Step 3: redirect the old URL
Keep visitors and search rankings by 301-redirecting every old URL to the same path on the new domain:
server {
listen 80;
listen 443 ssl;
server_name old-example.com www.old-example.com;
# ssl_certificate … (the old domain needs a valid cert for HTTPS redirects)
return 301 https://new-example.com$request_uri;
}
For a domain move, also use Google Search Console’s Change of Address tool. See WordPress redirects.
Special cases
HTTP → HTTPS only: same steps, with http://example.com → https://example.com, plus an HTTP → HTTPS redirect in Nginx. See WordPress SSL/HTTPS.
Subfolder → root: move the files (or change the Nginx root), update home and siteurl, search-replace https://example.com/blog → https://example.com, then redirect /blog/(.*) to /$1.
Multisite: also update wp_blogs, wp_site and wp_sitemeta, and DOMAIN_CURRENT_SITE in wp-config.php. Use wp search-replace --network. See WordPress multisite.
Troubleshooting
| Problem | Cause / fix |
|---|---|
| Redirects back to the old domain | WP_HOME/WP_SITEURL still set in wp-config.php, or a cache |
| Redirect loop | HTTPS behind a proxy or Cloudflare “Flexible” SSL. See too many redirects |
| Images or CSS still load from the old domain | Search-replace missed a variant, or a CDN or cache plugin setting |
| Mixed content warnings | http:// URLs left in content: search-replace them |
| Locked out of wp-admin | Use WP-CLI or wp-config.php constants |
Clear every cache layer afterwards: the page cache plugin, Nginx FastCGI cache, Redis object cache, and CDN.
Quick reference
| Task | Command |
|---|---|
| Set home/siteurl | wp option update home/siteurl 'https://new' |
| Replace in content | wp search-replace 'old' 'new' --all-tables --precise |
| Locked out | define('WP_HOME', …) in wp-config.php |
| Redirect old domain | return 301 https://new$request_uri; |
Related: WordPress staging site and WP-CLI guide.