To change a WordPress site’s URL you need to do more than edit one setting. WordPress stores its address in two settings, and the old address is also saved throughout your database in links, images, menus and plugin settings.
A clean URL change has four parts: update the two settings, replace the old URL in the database, redirect the old domain, and tell Google. This guide covers a change of domain or a switch from www to non-www on the same hosting. If you’re also moving to a new host, that’s a migration, which adds copying files and the database first.
Before you start
- Take a full backup of files and database. If you need a refresher, see how to back up and restore WordPress.
- Point the new domain’s DNS at your hosting and add it to your hosting account.
- Install an SSL certificate for the new domain before you switch, so it loads over HTTPS from the start. See adding SSL to WordPress.
- Pick a quiet time. Visitors may hit broken links for a few minutes while you work.
Step 1: Update the WordPress address settings
Go to Settings → General. You’ll see two fields:
- WordPress Address (URL), stored as
siteurl: where the WordPress core files live. - Site Address (URL), stored as
home: the address visitors type to reach your site.
On most sites both are the same. Enter the new address in each, with https:// and no trailing slash, and click Save Changes. WordPress will log you out, because your login cookie belongs to the old address. Log in again at the new one.
If the fields are greyed out, the values are set in wp-config.php, so change them there.
Using wp-config.php instead
If you’ve already changed the settings and can’t log in, or you’d rather set the address in code, add these lines to wp-config.php above /* That's all, stop editing! */:
define( 'WP_HOME', 'https://new-domain.com' );
define( 'WP_SITEURL', 'https://new-domain.com' );
These override whatever is in the database. They don’t change the stored values, so it’s still worth fixing the fields in Settings → General once you’re logged in. With WP-CLI you can update the stored values directly:
wp option update home 'https://new-domain.com'
wp option update siteurl 'https://new-domain.com'
Step 2: Replace the old URL in the database
Changing the settings doesn’t touch your content. Images in posts, links between pages, custom menu links, widgets and page builder layouts still point at the old domain. You need a search and replace across the database.
Don’t do this with a plain SQL REPLACE query in phpMyAdmin. WordPress and many plugins store settings as serialized PHP data, which records the length of every text value, like this:
s:22:"https://old-domain.com";
If the URL changes length and that number doesn’t, PHP can’t read the value. Widgets disappear, theme settings reset and plugin options break. Use a tool that understands serialized data.
With Better Search Replace
- Install and activate the free Better Search Replace plugin, then go to Tools → Better Search Replace.
- In Search for, enter
https://old-domain.com. In Replace with, enterhttps://new-domain.com. Match the format exactly, with no trailing slash on either. - Select all tables.
- Leave Replace GUIDs unchecked. GUIDs are permanent post identifiers, not links, and WordPress advises against changing them.
- Keep Run as dry run checked and run it. Review how many changes it would make.
- Uncheck dry run and run it for real.
If the site was ever on http:// or on the www version, run a second pass for that form of the old address too.
With WP-CLI
WP-CLI’s search-replace command also handles serialized data. Run a dry run first:
wp search-replace 'https://old-domain.com' 'https://new-domain.com' --all-tables-with-prefix --skip-columns=guid --dry-run
If the numbers look right, run the same command without --dry-run.
Page builders
Some page builders store layouts as JSON with escaped slashes, such as https:\/\/old-domain.com, which a normal search won’t match. Elementor has its own tool for this under Elementor → Tools → Replace URL. Afterward, regenerate the builder’s CSS files if it offers that option.
Finish this step by clearing every cache and visiting Settings → Permalinks, then clicking Save Changes to refresh the rewrite rules. If images or styles load over http afterward, see our guide to fixing mixed content.
Step 3: Redirect the old domain
Every old URL should send visitors and search engines to the same page on the new domain with a single 301 redirect. Keep the old domain registered and pointed at your hosting so the redirects keep working.
On Apache, if the old domain points at the same site folder, add this to the top of .htaccess, above the WordPress rules:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?old-domain\.com$ [NC]
RewriteRule ^(.*)$ https://new-domain.com/$1 [R=301,L]
On Nginx, give the old domain its own server block with return 301 https://new-domain.com$request_uri;. If your registrar or host offers domain forwarding, use it only if it keeps the full path, so /about/ goes to /about/ and not to the homepage.
Test a few old URLs, including deep pages and images. Each one should land on the matching new URL in one hop. If you get a loop, see too many redirects. Google recommends keeping site move redirects in place for at least a year, and longer is better.
Step 4: Tell Google with Change of Address
- In Google Search Console, verify both the old domain and the new domain as properties.
- Open the old property and go to Settings → Change of address.
- Select the new property and submit. Search Console checks that the old homepage redirects to the new one.
- Submit your sitemap, usually
/wp-sitemap.xmlor the one your SEO plugin creates, in the new property.
The Change of Address tool is for moving to a different domain or subdomain. It isn’t needed for an http to https switch, where the redirects alone do the job.
Check these afterward
- Contact form notifications and the “from” address on site emails. A new domain needs its own email authentication records, or messages may land in spam. See WordPress not sending emails.
- Hardcoded URLs in theme files, custom CSS or code snippets.
- CDN, caching and security plugin settings that list the domain.
- Premium plugin licenses tied to a domain, and payment gateway webhooks.
- Analytics, Google Business Profile and social profile links.
Want someone to handle it?
If you’ve already changed the URL and the site is broken or you’re locked out, our $79 one-time fix sorts it out, usually within 24 hours, fixed or your money back. Planning a domain change or a move to new hosting? Our migration service handles the whole thing, and our Care Plans keep it running smoothly afterward.