Weaver's Loom

Main menu

Changing the Domain Name on WordPress Multi-site

I created a WordPress site for a client who needed to support both English and Español versions of their content, which involved using a plugin called MultilingualPress that creates relationships between sites for each language.

I developed the site locally on my server, and then after they created some content, migrated it to their hosting service.

For some reason, WordPress stores information about the site in various places throughout the database, so moving from one site to another is not just a simple matter of moving the content and database to the new server.

First I made a backup of the database and the content (and did an export of the content via the WordPress site for an extra level of backup). Then I imported the database to the new site, and content copied to the right place on the new server. I updated the wp_config.php file with the new database credentials, but at this point nothing would work because everything still had my original domain name on it.

So the next thing was to add a setting in the wp_config.php file for Muti-Site to use the new server name.

1

2

3

4

5

6

7

8

9

10

11

12

/* Multisite */

define('WP_ALLOW_MULTISITE',true);

define('MULTISITE',true);

define('SUBDOMAIN_INSTALL',false);

define('DOMAIN_CURRENT_SITE','www.hostname.org');

define('PATH_CURRENT_SITE','/');

define('SITE_ID_CURRENT_SITE',1);

define('BLOG_ID_CURRENT_SITE',1);

define('CUSTOM_USER_TABLE','wp_users');

define('CUSTOM_USERMETA_TABLE','wp_usermeta');

Changing the ‘DOMAIN_CURRENT_SITE’ to the name of the server, gives the multisite the information it needs.

Next to complete, we have to tweak a few things in the database.

First is the table named ‘wp_site’, which needs the same information as the wp_config.php file:

MySQL

1

2

3

4

-- Site

UPDATE`newdb`.`wp_site`

SET`domain`='www.hostname.org'

WHERE`newdb`.`id`=1;

Next is the table ‘wp_blogs’, which are a list of the sites created for the multisite. This table has rows for each site, so in this case there were two that were updated:

MySQL

1

2

3

4

5

6

7

-- Blogs

UPDATE`newdb`.`wp_blogs`

SET`domain`='www.hostname.org'

WHERE`newdb`.`blog_id`=1;

UPDATE`newdb`.`wp_blogs`

SET`domain`='www.hostname.org'

WHERE`wp_blogs`.`blog_id`=2;

Then each site has its own options in ‘wp_options’ which were also updated with the new hostname (both the siteurl and home options):

MySQL

1

2

3

4

5

6

7

8

9

-- English

UPDATE`newdb`.`wp_options`

SET`option_value`='http://www.hostname.org/'

WHERE`wp_options`.`option_name`IN('siteurl','home');

-- Espanol

UPDATE`newdb`.`wp_2_options`

SET`option_value`='http://www.hostname.org/es/'

WHERE`wp_2_options`.`option_name`IN('siteurl','home');

In some cases, there are options for themes to be updated, which gets a bit more tricky. If you find an option that has the old URL for a theme/plugin. This value is stored under a key specific to the theme/plugin in the options table . For instance the All-in-One Calendar plugin stores the value for it’s theme under an option named ‘ai1ec_current_theme’.

That value is data format, stored as type/length/value pairs. It resembles a JSON object, (formatted below to make it easier to read):

The only trick to this is make sure you change the length to match, so the update in this case would change from “old” to “hostname”, adding 5 characters, making the update be (this is per site in the multisite):

1

2

3

4

5

--Note theme options are the trickiest,requiring updating the JSON with the value andmaking the newlength match the value

After updating the data (and committed to the DB), it’s a good idea to run a final query to see if the old name exists on any of the options for each site.

It is possible that other content will remain that is still pointing at the old host, since there are other tables that reference content in a non-relative way, but this will be pretty close to what you need.