The Problem
You bought a better domain, rebranded, or moved your site to a permanent address. Now WordPress still points everything at the old URL. Images load from the wrong host. Internal links return 404. The admin redirects you back to the old domain the moment you log in. A clean domain change touches three places. WordPress settings hold the public URL. The database stores the URL inside hundreds of rows. Redirects send old visitors to the new home. This tutorial covers each step so links, logins, and media work the moment you flip the switch.
What You’ll Need
- WordPress version: 6.0 or newer, block editor or classic editor
- Permissions needed: Administrator role on WordPress, hosting panel access or FTP, and phpMyAdmin or another database client
- Time to complete: 45 minutes from start of backup to verified working site
- Difficulty level: Intermediate, with some command-line or file-editor comfort required
- Prerequisites: New domain DNS pointed at your hosting, a fresh full site backup, and an SSL certificate already issued for the new hostname
Step 1: Back Up the Database and Files
Open your hosting control panel and take a full site backup before you touch anything. Most hosts label this Backups or Snapshots inside the main dashboard. Download both the database export and the files archive to your computer. You can then restore if a step goes wrong. If your host does not include backups, install UpdraftPlus. Run a backup to a remote location like Dropbox and confirm it finished. To rehearse the full swap before committing, run it on a copy first. The steps live in How to Set Up a WordPress Staging Site Step by Step.
[SCREENSHOT: hosting-panel-backup-button]
A domain change rewrites thousands of database rows. Without a backup you cannot undo a bad replacement.
Step 2: Update the WordPress and Site Address
Navigate to Settings → General in your WordPress dashboard. Change the WordPress Address (URL) and Site Address (URL) to your new domain. Both fields must include https:// and match exactly. Click Save Changes. WordPress logs you out because the cookie is tied to the old domain.
[SCREENSHOT: settings-general-url-fields]
If you get locked out before changing the rest, restore access via wp-config.php. Add these two lines above the comment that reads /* That's all, stop editing! */.
What this does: Forces the URLs in code so you can log in while the database has the old values.
define( 'WP_HOME', 'https://your-new-domain.com' );
define( 'WP_SITEURL', 'https://your-new-domain.com' );
Step 3: Run a Database Search and Replace
Install the free plugin Better Search Replace from Plugins → Add New. Activate it and open Tools → Better Search Replace. In the Search for box, paste the old domain (https://old-domain.com — no trailing slash). In the Replace with box, paste the new domain. Select all tables in the list. Tick Run as dry run? and click Run Search/Replace.
[SCREENSHOT: better-search-replace-dry-run]
Review the report. When the dry run looks correct, untick Run as dry run? and run it again. The plugin handles serialized PHP data correctly. A manual SQL UPDATE would corrupt widget settings and theme options.
Step 4: Flush Permalinks and Rewrite Rules
Open Settings → Permalinks in the dashboard. Do not change any setting. Click Save Changes. WordPress regenerates the .htaccess rules to match the new domain.
[SCREENSHOT: permalinks-save-changes]
If your site uses Nginx, ask your host to reload the configuration or restart PHP-FPM so cached rewrite rules refresh. If a CDN sits in front of your site, purge every cached URL. See How to Set Up a Cloudflare CDN for WordPress Step by Step for the purge button location.
Step 5: Add 301 Redirects From the Old Domain
Open the .htaccess file in the root folder of the old domain through your hosting file manager. Paste this rule at the top, before any existing WordPress block.
What this does: Sends every visitor and inbound link from the old domain to the new one with a permanent 301 status.
RewriteEngine On
RewriteRule ^(.*)$ https://your-new-domain.com/$1 [R=301,L]
[SCREENSHOT: htaccess-301-redirect-rule]
Save the file. If you no longer control the old domain, skip this step. The only effect is preserving inbound links and direct-traffic visitors.
Step 6: Verify Logins, Media, and Internal Links
Log in to https://your-new-domain.com/wp-admin/. Open three Posts on the front end and check that images load without console errors. Test a comment, a form submission, and the contact page. Open Chrome DevTools with F12 and click the Network tab. Reload the homepage. Confirm zero requests still point at the old domain.
[SCREENSHOT: devtools-network-tab-verification]
Visit the old domain in an incognito window. Every URL should land on its new-domain counterpart.
Troubleshooting
Error: “Too many redirects” after saving the new URL.
Fix: Clear your browser cache. Then check wp-config.php for stale WP_HOME or WP_SITEURL constants and update them.
Error: Images return 404 after the search and replace.
Fix: Run Better Search Replace again and check the _postmeta and _options tables explicitly. Re-upload featured images if a custom plugin stored absolute paths.
Error: Admin redirects to the old domain on every login.
Fix: Open phpMyAdmin, edit the wp_options table, and update the siteurl and home rows to the new domain. Clear all object cache and refresh.
Error: SSL warning on the new domain.
Fix: Confirm the certificate was issued for the new hostname in your hosting SSL panel before pointing DNS.
Quick Recap
- You backed up the full site before touching the database.
- You updated WordPress Address and Site Address in Settings → General.
- You ran a serialization-safe search and replace across every table.
- You flushed permalinks, added a 301 redirect from the old domain, and verified logins and media.
For a full hosting move, follow How to Migrate WordPress to a New Host Step by Step. The official WordPress Codex page on Changing the Site URL documents the same fields.
