Change the basedomian of your blog

Sometimes you have to change the base domains of your blog. Therefore there are the following possibilities (ATTENTION: These snippets are thought to be used with a single site installation):

Backend settings

If you have access to the Backend of your WordPress installation, you can change the basedomain of your blog under:

Settings -> General -> WordPress Address (URL)


Settings -> General -> Site Address (URL)

This option is useful if you want to move your site to another domain. The other side of the coin is, that you have to change the domains before moving the site and that your old site won’t be available from this moment on until the new site is ready.

wp-config entries

You can add the following lines to your wp-config.php to set the siteurl and home-URL. But that’s not a good idea because in this case you can’t use the Backend anymore to change these values.


Nevertheless it’s a good way to correct the domains temporarily to get into the settings if you accidentally changed the settings wrong. After correction you can remove the constants.

Database changes

But sometimes it is necessary to change these values direct in the database (f.e.: moving installation, buildup a development environment …). In these cases you can use a phpAdmin installation or you can directly write queries against the database. The relevant table is wp_options. The following queries can be used to look for and change the necessary table fields:

Show values for siteurl (WordPress Address) and home-URL (Site Address):

mysql> SELECT * FROM wp_options WHERE option_name LIKE 'siteurl' OR  option_name LIKE 'home';

This should result in a view like this:

| option_id | option_name | option_value                 | autoload |
| 2         | home        |   | yes      |
| 1         | siteurl     |   | yes      |
2 rows in set (0.00 sec)

Now you can change the values with this query:

mysql> UPDATE wp_options SET option_value = '' WHERE option_name = 'siteurl' OR option_name = 'home';

After this the table entries from above should look like this:

| option_id | option_name | option_value                 | autoload |
|         2 | home        | | yes      |
|         1 | siteurl     | | yes      |

Now you need to check out if there are any direct connections to the old domain inside your blog posts:

mysql> SELECT * FROM  wp_posts WHERE post_content LIKE '';

If there are any findings, you can search and replace them via:

mysql>  UPDATE wp_posts SET post_content = REPLACE(post_content,'','');

WordPress Commandline Tool

Another option is the use of the WP-CLI tool ( This tool has a wide range of commands to deal with your WordPress installation (

The one you need to replace all occurrences of your old domain in the database is:

$> wp search-replace '' ''

Or if you want to change the domains only:

$> wp option update siteurl ''
$> wp option update home ''

A description of the installation of wp-cli can be found here.

Further information

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.