How to change the WordPress URL: switch domains or move to HTTPS
To change the address of a WordPress site, update the two site addresses in Settings > General, or the siteurl and home values in the database, and then replace the old address that is still stored in the content. Next, create a 301 redirect from the old address to the new one, so you don’t lose visits or Google rankings.
This article is for anyone switching domains, moving the site from http to https, or fixing a wrong address that took the site offline. It covers both address fields, fixing the address through wp-config.php and phpMyAdmin, carefully replacing the old addresses in the database, and redirects.
Before you begin
- Make a full backup first: the site’s files and the database. Every step below can go wrong if the address is mistyped, and the backup undoes everything.
- Have access to cPanel, in case the WordPress dashboard goes down during the change.
- If you’re switching domains, the new domain must already be pointing to the hosting and open in the browser, even if it shows the old site or a blank page.
- For
https, the SSL certificate must be installed and working first. See how to install SSL in cPanel.
What are the two WordPress addresses?
WordPress stores two addresses, which are the same on most sites:
| Field in the dashboard | Name in the database (wp_options) |
What it’s for |
|---|---|---|
| WordPress Address (URL) | siteurl |
Where the WordPress files are located |
| Site Address (URL) | home |
The address visitors type to open the site |
They only differ when WordPress is installed in a subfolder but the site appears at the root of the domain. If your site is a standard installation, use the same address in both fields, with https:// or http:// at the start and no slash at the end.
How to change the address from the WordPress dashboard
This is the simplest route, when you can still log in to the dashboard.
- Log in to the dashboard at
yourdomain.com/wp-admin. - Go to Settings > General.
- Change WordPress Address (URL) and Site Address (URL) to the new address, for example
https://yourdomain.com. - Click Save Changes.
After saving, WordPress asks you to log in again, and the old address stops opening the dashboard. So double-check the text you typed before you click save: a typo here takes the dashboard offline.
If both fields appear gray and can’t be edited, the address is fixed in the wp-config.php file. In that case, follow the next section.
How to fix the address through wp-config.php
The wp-config.php file can fix the addresses and, when it does, it takes precedence over the database. It’s also a quick way to recover a site that became inaccessible because of a wrong address.
- In cPanel, open the File Manager and go to the site’s folder.
- Download a copy of
wp-config.phpand open the original with Edit. - Look for lines with
WP_HOMEandWP_SITEURL. If they exist, change the address. If they don’t, add the following above the comment/* That's all, stop editing! */:
define( 'WP_HOME', 'https://yourdomain.com' );
define( 'WP_SITEURL', 'https://yourdomain.com' );
- Save and open the site.
These lines are an emergency fix. With them in the file, the field in the dashboard stays locked. After logging in to the dashboard and confirming everything works, you can remove them so the dashboard controls the addresses again, or keep them if you prefer a fixed address in the file.
How to fix siteurl and home through phpMyAdmin
Use this method if the dashboard won’t open and wp-config.php doesn’t have the lines above.
- In cPanel, open phpMyAdmin. Before changing anything, click the Export tab for the site’s database and download a copy.
- If you’re not sure which database it is, open
wp-config.phpand look for theDB_NAMEline. - Open the table that ends in
_options, such aswp_options. Your site’s prefix may be different. - On the Browse tab, find the rows where
option_nameissiteurlandhome. - Click Edit on each one and replace the
option_valuewith the correct address. - Save, clear your browser cache and open the site.
How to replace the old address stored in the content
Changing siteurl and home doesn’t change what is already stored in pages, posts, menus and plugin settings. Images, internal links and theme settings may still point to the old address. On a site that has moved to https, this causes a mixed-content warning: the page loads, but the padlock disappears or some images don’t appear.
Don’t make the change with a simple SQL “find and replace” across the whole database. WordPress and many plugins store data in serialized format, which records the size of each text string. If the new address has a different length than the old one, a direct replacement breaks that record, and the affected settings stop working. The change requires a tool that understands serialized data:
- A search and replace plugin, such as Better Search Replace, installed like any other plugin. See how to install a plugin in WordPress.
- WP-CLI, if your server gives command-line access, using the
search-replacecommand.
With either one, follow this order:
- Make a copy of the database.
- Run a test first (in the plugin, the simulation option; in WP-CLI,
--dry-run) and see how many replacements would be made. - Replace the old address with the new one, in full, with
http://orhttps://. - Leave the
guidcolumn out. It’s the internal identifier for posts and media, and WordPress recommends not changing it. - Check the site and clear any cache.
An example WP-CLI command, for those with access:
wp search-replace 'http://yourdomain.com' 'https://yourdomain.com' --skip-columns=guid --dry-run
If the test result looks as expected, run the command again without --dry-run.
How to redirect the old address to the new one
A 301 redirect tells visitors and search engines that the address has permanently changed. Without it, anyone who visits the old address gets an error, and links pointing to it stop leading to the site.
Redirect from http to https
In the .htaccess file in the site’s folder, above the # BEGIN WordPress line, after downloading a copy of the file:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
If the file doesn’t show up, turn on Show Hidden Files in the File Manager settings. To see what the default file looks like, see .htaccess in WordPress: how to find and create the default file.
Redirect an old domain to the new one
If the old domain points to the same site folder, the rules below send all of its addresses to the same path on the new domain:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^(.*)$ https://yourdomain.com/$1 [R=301,L]
Replace olddomain.com and yourdomain.com with your domains. If your cPanel has the Redirects option, it does the same thing without editing the file by hand. The step-by-step guide is in how to redirect a domain in cPanel.
After changing the address
- Open the site in a private window, browse pages, posts and images, and check that the padlock appears.
- Under Settings > Permalinks, click Save Changes without changing anything. This rewrites the address rules.
- Clear the site’s cache. See what a caching plugin is for in WordPress.
- If you switched domains, let the places that cite the old address know: social networks, email signatures, Google Search Console and business listings.
- Keep the old domain’s redirect and renewal active, so old links keep working.
If you’re also moving the site to a different hosting provider along with the domain, see how to migrate a WordPress site to MigraCloud. If you need help with the change, contact MigraCloud.
Frequently asked questions
How do I change the WordPress URL?
Go to Settings > General, change the WordPress Address (URL) and Site Address (URL) fields, and save. If the dashboard won’t open, fix the siteurl and home values in phpMyAdmin or fix the addresses in wp-config.php. Then replace the old address that is still in the content.
What’s the difference between siteurl and home in WordPress?
siteurl is the address where the WordPress files are located, and home is the address visitors use to open the site. On a standard installation, the two are the same. They only differ when WordPress is in a subfolder and the site appears at the root.
What should I do if the site went down after changing the address?
The address was most likely mistyped. Fix it through wp-config.php, with WP_HOME and WP_SITEURL, or through phpMyAdmin, in the _options table. In both cases, download a copy before editing.
How do I move WordPress from http to https?
Install the SSL certificate, change both addresses to https://, replace the old http:// in the content with a tool that understands serialized data, and create the 301 redirect in the .htaccess. Test the site in a private window at the end.
Can I replace the old address directly in the database with SQL?
It isn’t recommended. Serialized data stores the length of the text, and a direct replacement with an address of a different length corrupts those records. Use a search and replace plugin or WP-CLI, always with a test beforehand and a copy of the database.
Does changing domains make a site lose its Google rankings?
Rankings may fluctuate, but a 301 redirect from each old page to the matching page on the new domain reduces the risk. Keep the redirect active and let Google know through Search Console, using the address change tool.
Why is the address field gray in the dashboard?
Because the address is fixed in wp-config.php, with WP_HOME and WP_SITEURL. To edit it from the dashboard again, remove those lines from the file after downloading a copy.
Do I need to redo the SSL certificate when changing domains?
Yes. The certificate is valid only for the domain it was issued for, so the new domain needs its own certificate. Install it before moving the site to https.