Change Your WordPress Website’s Site URL and Home URL (WordPress 2022) • Lightweb Media

Joel Burghardt
January 13, 2022
5 minutes reading time

Changing your WordPress URL can have many reasons: You may be changing your existing domain, want to move your existing domain to a subdomain, operate a staging environment or want to switch your WordPress site to SSL (from http to https).

In the following step-by-step instructions, we will show you what options there are for changing your site URL and your home URL. First of all, we will clarify the two terms and their differences, so that you don’t find it difficult to understand the instructions.

You should always create a backup of your files & database before making changes.

In advance: For all those who only wanted to find the code for the Config.php 🙂

define( 'WP_HOME', 'https://www.meine-website.de' );
define( 'WP_SITEURL', 'https://www.meine-website.de' );

Site URL vs Home URL and their differences

the Home URL (website address; WP_HOME) denotes the web address of your WordPress website. This is interesting for you because it is entered by your customers in the web browser – your customers and website visitors are looking for this URL. (www.meine-webseite.de)

the site url (WordPress address; WP_SITEURL) on the other hand is not relevant for your customers, only for you. By default, this is the same as the home URL.

The site URL indicates where your WordPress files are located. So your folders, media files, plugins, themes etc.

use case

Your WordPress is installed at https://www..mein-website.de/wordpress/. But you want the page to be accessible at https://www.meine-website.de.

The site URL is: https://www.meine-website.de/wordpress/
The home URL is: https://www.meine-website.de

Why and When Should You Change Your WordPress URL?

Basically, the domain of your website should be aligned and planned for the long term. There are many reasons for this, not the least of which is customer loyalty and brand awareness. So you want to avoid changing your site & home URL as much as possible.

However, the URL often has to be changed – for example when your hosting provider moves, when setting up staging/dev environments and the like.
These two settings are especially useful if you want to develop the new version of your website in a subfolder and move it to the root directory when it’s done.

Now you have two options, either you seek professional help or you do it à la “DIY“ yourself. We recommend the latter because it is not a difficult process and can be done quickly.

6 ways to change the WordPress URL of your website:

In the following, we will show you six ways how you can change the WordPress URL of your website yourself. Of course there are many more variants, but these are usually very technical and unnecessarily complicated and ultimately lead to the same result. The six options are:

  1. Change URL directly from the admin dashboard
  2. Change URL via wp-config.php file
  3. Change URL via “relocate” constant
  4. Change URL in your database
  5. Change URL via CLI.
  6. Database Replace with Plugins

Change WordPress URL directly from the admin dashboard

Probably the easiest method is to change the WordPress URL directly via the admin area in the backend. To do this, you simply have to go to “General” under “Settings”. The current URL of your website will now be displayed. You change this and save it. In the case of an SSL certificate, you should end the domain with a “https“ enter before.

WP Settings Website and WordPress address

If the fields in your admin area are greyed out, you need to use the next method since you have hard coded values ​​on your WordPress site.

Change WordPress URL via wp-config.php file

If the fields are now greyed out, the wp-config-php file must be changed. The wp-config.php file can be found in the root directory of your WordPress website. Once you’ve found it, open it and first copy the code into a NotePad to be on the safe side. After that you can use the following code. Paste the code in this line that tells you to stop editing.

define( 'WP_HOME', 'https://www.meine-website.de' );
define( 'WP_SITEURL', 'https://www.meine-website.de' );

If you have an SSL certificate, you can replace the “http” with “https”. After that, all you have to do is save and close. If you now go back to your admin area under “Settings” à “General”, you will see both fields grayed out and provided with your new URL.

Change WordPress URL with relocate constant

This method also works via the wp-config.php file. Here you have to insert the following code:

define('RELOCATE',true);

The code should be placed at the end just before “That’s all, stop editing!” is written.

  • After pasting the code snippet, log in www.meine-webseite.de/wp-login.php a.
  • Now change the site or home URL under settings.
  • After that, be sure to delete the constant “relocate“ out of the wp-config.php again.

Change WordPress URL in your database

If the first three methods don’t work, you can change your WordPress URL directly via the database of your WordPress website. For this you need access to your phpMyAdmin area. This usually works via your hosting provider.

Make a backup before making any changes to the database. If you are unsure, just ask us.

We are happy to change the URL of your website

If you are inside, you must use the table wp_options search. Often it will be that the table has a different prefix and for example xyz_options called. Once you find the table, open it and look for the column option_name. Your site URL is hidden there. Then click on “edit” or double-click in the field and enter below option_value Enter the new URL of your WordPress website.

Change site url and home url of your wordpress website wp site url change home url in database wordpress urlwp_options – view in database

Change WordPress URL using the Command Line Interface (CLI).

This variant is a bit more difficult and demanding, since you have to be familiar with the WP-CLI. In order to communicate with a shell (in most cases Bourne shell, Bash or Z-shell on a Linux system), you need SSH access.

To edit entries in your wp_options you need the following command:

wp option <KEY> <VALUE>

So if we want to change the home url and the siteurl:

wp option update home 'https://www.meine-website.de'
wp option update siteurl 'https://www.meine-website.de'

These entries are then overwritten in the WordPress database in the wp_options table.

To check, you can simply have the values ​​of your option displayed in the shell again:

wp option get siteurl
wp option get home

Database replacement via plugins

If the first method doesn’t work and you’d rather stay away from the technical work, we recommend the Better Search Replace and Velvet Blues Update URLs plugins. With these two plugins you can replace and revise all paths and URLs of your database. I will deal with both plugins again separately in another post.

Important

Always make a database backup before making changes to the database.

The redirects after changing your site url

After changing your site URL, you always have to make sure that your website visitors are also redirected to the correct URL. To do this, contact the support of your hosting provider and find out whether there is a wildcard redirection in the C-Panel. Here you can then check whether your changed URLs are correctly redirected and forwarded.

I always use the redirect via .htaccess, which I will explain in another post.

Need help with WordPress?

Your WordPress has errors, you need technical support, help or advice? You don’t know how to deal with backups and administration?
No problem, WordPress is in our DNA.
We’ll help you with that Installation, administration, maintenance and support