WordPress stores its own address in the database and builds every link from it. When you move to a new domain, add HTTPS or move from a subfolder, you must update that address, and then update the old links saved inside posts and settings.
Before you start
- A fresh backup. In cPanel → JetBackup or with a backup plugin, save files and the database first.
- The new domain already points to your hosting and is added in cPanel → Domains → Domains with the correct document root.
- A valid SSL certificate on the new domain if the new URL uses
https://.
Option A: change it in the dashboard
- Log in to
/wp-adminand open Settings → General. - Change WordPress Address (URL) and Site Address (URL) to the new address. Both are normally identical.
- Click Save Changes. You are logged out and must log in again on the new address.
Warning: A typo here locks you out of the dashboard. If that happens, use option B or C to fix it.
Option B: set it in wp-config.php
Open cPanel → Files → File Manager, edit wp-config.php and add these lines above the /* That's all, stop editing! */ comment:
define( 'WP_HOME', 'https://newdomain.com' );
define( 'WP_SITEURL', 'https://newdomain.com' );These values override the database and grey out the fields in Settings. Use them to recover a broken site, then remove them once the database is correct if you want to manage the URL from the dashboard again.
Option C: edit the database in phpMyAdmin
- Open cPanel → Databases → phpMyAdmin and select the site's database (check
DB_NAMEinwp-config.php). - Open the
optionstable with your prefix, for examplewp_options. - Edit the rows
siteurlandhomeand set both to the new address without a trailing slash.
Replace old links in content
Posts, menus, widgets and page builder data still contain the old domain. Replace them with a serialisation-safe tool, never with a plain SQL REPLACE, because many values are serialised PHP arrays that break when string lengths change. Use WP-CLI or a plugin such as Better Search Replace.
wp search-replace 'https://olddomain.com' 'https://newdomain.com' --all-tables --dry-runRun it once with --dry-run, review the counts, then run it again without that flag.
Redirect the old domain
Keep your search rankings by sending visitors from the old domain to the new one with a 301 redirect. In cPanel → Domains → Redirects choose Permanent (301), select the old domain, enter the new URL and enable Wild Card Redirect so every path is kept.
Troubleshooting
- Redirect loop after switching to HTTPS: check that no plugin and no
.htaccessrule force the opposite scheme. - Images missing: the search and replace was skipped or limited to some tables.
- Login page reloads: clear cookies for both domains and flush the LiteSpeed cache.
- Mixed content warnings after moving to HTTPS: some links still use
http://; run the search and replace again for thehttp://form of the domain.
Moving from a subfolder to the root
A common variant is moving https://example.com/blog to https://example.com. The URL change is the same, but you must also move the files up one level in File Manager, or keep them in the subfolder and copy index.php and .htaccess to the root, editing the require line in index.php to point to /blog/wp-blog-header.php. Either way, finish with the search and replace and re-save permalinks.
