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)

and

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):

This should result in a view like this:

Now you can change the values with this query:

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

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

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

WordPress Commandline Tool

Another option is the use of the WP-CLI tool (http://wp-cli.org/). This tool has a wide range of commands to deal with your WordPress installation (http://wp-cli.org/commands/).

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

Or if you want to change the domains only:

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.