Home - Changing the WordPress URL: Customizing the Site Address
On this page

Changing the WordPress URL: Customizing the Site Address

Picture of David Ladiges
David Ladiges
Technical Lead
Changing the WordPress URL: Customizing the Site Address
Changing the WordPress URL: Customizing the Site Address

Your company has a new name, you're switching from a temporary domain to the actual domain, or your site needs to switch from http to https. You can change your WordPress URL by updating the WordPress Address and Site Address under Settings > General Update it, then replace the old URL in the database with the new one, and set up a 301 redirect from the old address to the new one. It’s a good task to do yourself, but it’s also one of the few jobs where you can really lock yourself out. I’ll share the order I follow myself, along with a last-resort solution in case things do go wrong.

The WordPress Address and the Site Address

The WordPress Address is where the WordPress files are located; the Site Address is the address visitors use to access your site. For almost every site, they are exactly the same, and that’s how you should keep it. They differ only if WordPress is located in a subfolder while your site needs to run on the main domain. Internally, these two settings are called siteurl and home, and they're listed in the table wp_options from your database.

What many people don't realize is that those two fields are only part of the story. WordPress also stores your address within the content itself. Every internal link you’ve ever posted and every image you’ve inserted is stored in the database with the full old address. If you only update those two fields, all those links and images will continue to point to the old domain. A true URL change therefore always consists of two parts: changing the address and updating the database. How WordPress uses files and the database together is explained in What WordPress is and what it's used for.

There’s one more thing to consider. Some of that data is stored in serialized form in the database, a storage format that also records the length of each text string. If you replace the old URL with a simple search-and-replace in phpMyAdmin, that length will no longer be correct, and your theme or page builder’s widgets and settings will be lost. Therefore, always use a tool that takes this into account.

What to Do Before Making Changes

Don't start changing a URL until you have a fresh backup ready and the new address is already working. Make a full backup of your files and your database, and make sure you know how to restore them. This is because you won’t be able to access a site with an incorrectly stored address through the dashboard. You can read about how to create and restore backups in The Guide to Backup and Migration.

Also, make sure the new domain is already pointing to your hosting and has an SSL certificate. If you update the DNS records, it will take a little while for the change to take effect everywhere. You can find out how domains, DNS, and email are connected in Domain, DNS, and Email for WordPress. With Surver, every site receives a free Let’s Encrypt certificate that is automatically renewed as long as the DNS points to Surver. So wait until the padlock appears on the new domain before switching over in WordPress. If you’re only switching from http to https on the same domain, this is the only preparation you need to do besides backing up your site.

The Safe Sequence

This order prevents you from ending up with a site that works only partially at two addresses at the same time.

  1. Verify that the backup is ready and that the new domain with SSL is accessible.
  2. Change under Settings > General Change the WordPress Address and Site Address to the new URL, and click Save changes. WordPress will log you out; then log in at the new address.
  3. In the database, replace the old URL with the new one using a plugin such as Better Search Replace, or via WP-CLI with wp search-replace 'https://oud.nl' 'https://nieuw.nl' --dry-run. The latter option first shows you what will change without saving anything. If everything looks good, execute the command without --dry-run.
  4. Set up a 301 redirect from the old domain to the new one so that visitors and search engines are automatically directed to the correct location.
  5. Clear the cache and navigate through the site, including the menu, forms, and login page.

To learn how a 301 redirect works and why you shouldn't use a 302, read What are redirects?. Keep the old domain active for quite some time, because without it, the redirect won’t work either. If you switch to a new domain, report the change in Google Search Console using the change-of-address tool. If you just want to clean up the URLs of individual pages, you don’t need to go through this entire process; see Customize permalinks.

Mixed content after switching to HTTPS

If the padlock icon disappears after the switch, your page is likely still loading files from the old HTTP address. This is called mixed content. The page itself is secure, but an image, script, or font is still being loaded over an unsecured connection. Step 3 usually resolves this, since the search-and-replace function also updates those references. If the padlock is still missing, press F12 to open your browser’s developer console. It will show exactly which files are still loading via HTTP. Often, these are hard-coded references in your theme’s settings, a widget, or a page builder, and you’ll need to change them manually.

Locked out? Here's how to fix the address

If your site is blank or inaccessible after the change and the dashboard is no longer responding, this can almost always be fixed. You just need access to your files or your database.

Via wp-config.php

Open the file using File Manager or FTP wp-config.php in the root directory of your site, and add these two lines above the line that says “That's all”: define('WP_HOME', 'https://jouwdomein.nl'); and define('WP_SITEURL', 'https://jouwdomein.nl');. These take precedence over the values in the database, so your site will be accessible again right away. Afterward, make sure to configure the settings correctly and remove the rules. If this is your first time working with this file, please read Editing WordPress Code Safely.

Via phpMyAdmin

In phpMyAdmin, open the table wp_options, find the rows siteurl and home and adjust the value there. Your table prefix may be different from wp_, you can see that in wp-config.php. If neither of these works, restore the backup and start over.

With our shared hosting plans, you'll find File Manager, phpMyAdmin, SSH, and WP-CLI all within cPanel, so you can perform these tasks without any additional software. You can restore a backup for free using JetBackup 5. With our Managed WordPress Hosting you have those resources at your disposal. If you switch to a different host, this is only half the work, and you'll follow The Step-by-Step Guide to Moving a Website. If you don't want to keep track of the updates yourself after the switch, then WordPress maintenance that for you every month.

Frequently Asked Questions

Will I lose my rankings on Google if I switch domains?

A little fluctuation is normal, but with a 301 redirect for each URL and a notification in Search Console, most of your accumulated value will be preserved. Keep the old domain and leave the redirects in place.

Do I also need to change the URL if I'm just switching to https?

Yes. Set both addresses to https, replace http:// by https:// in the database and redirect all HTTP traffic using a 301 redirect. Otherwise, you'll end up with mixed content.

Can Surver handle the URL change for me?

Yes, if it's part of a move to Surver. The moving service It's included for free with every package, and we'll also set up the site URL and redirects correctly. Your email, DNS records, and domain will be transferred as well.

Have a question about your website or hosting?

Our team is ready to help you! Leave your details and we'll get back to you with no obligation.

Share this article:

Ask your question

Have a question about your website, hosting or WordPress? Enter your details below and we'll get back to you as soon as possible with a personalized answer.

You don't need any technical knowledge. We are happy to think with you.

Ask your question