changing the URL for multisite network
wp-config.php
.htaccess
(if needed, in case custom modifications were made to the file)There are various ways of doing this:
wp-cli
to update the site URL (not sure how effective on multisite networks, also redundant as it will not update post content)Change URL from the Dashboard > Settings first and see how/where it updates the values in the database. Another option is changing it via wp-cli
1wp option update home 'http://newsiteurl.com'
2wp option update siteurl 'http://newsiteurl.com'
Use this recommended search and replace tool by Interconnect IT to run your queries (you can also do a safe dry run). You should be wary of updating database fields, something to do with WordPress storing data in serialized arrays and PHP relying on the string length of each piece of data to be able to read it properly.. ref
Do this for all sites in the network
Table name | Desc. | Notes |
---|---|---|
wp_options | Select the options table and look for the entries named siteurl , home (and fileupload_url ) | required to have the http:// at the beginning |
wp_site | can NOT have http:// or a trailing slash at the end of the domain name | |
wp_sitemeta | Select the option named siteurl name. | required to have http:// at the beginning and a trailing slash at the end |
wp_blogs | Select any entries in the domains column that have the old domain | can NOT have http:// or a trailing slash at the end of the domain name |
wp_#options | Each sub-site will have sets of tables that correspond to the blog_id in the wp_blogs table. You need to go to the wp#_options table, where # corresponds to the blog_id , and update the siteurl and home settings in that table. | |
wp_posts | URL is mentioned in the guid and sometimes in post_content |
1-- find the places where the URL is used
2
3-- Main domain site
4SELECT * FROM `wp_blogs` WHERE `domain` LIKE CONCAT('%', 'old.siteurl.com', '%'); -- has the main site for the entire network and paths for individual sites
5SELECT * FROM `wp_site` WHERE `domain` LIKE CONCAT('%', 'old.siteurl.com', '%');
6SELECT * FROM `wp_sitemeta` WHERE `meta_value` LIKE CONCAT('%', 'old.siteurl.com', '%');
7SELECT * FROM `wp_options` WHERE `option_value` LIKE CONCAT('%', 'old.siteurl.com', '%');
8SELECT * FROM `wp_posts` WHERE `guid` LIKE CONCAT('%', 'old.siteurl.com', '%'); -- this guid is kind of like permalink, mentions the entire site URL
9SELECT * FROM `wp_posts` WHERE `post_content` LIKE CONCAT('%', 'old.siteurl.com', '%'); -- media file links
10SELECT * FROM `wp_postmeta` WHERE `meta_value` LIKE CONCAT('%', 'old.siteurl.com', '%');
11
12-- Additional sites
13SELECT * FROM `wp_2_options` WHERE `option_value` LIKE CONCAT('%', 'old.siteurl.com', '%');
14SELECT * FROM `wp_2_posts` WHERE `guid` LIKE CONCAT('%', 'old.siteurl.com', '%');
15SELECT * FROM `wp_2_posts` WHERE `post_content` LIKE CONCAT('%', 'old.siteurl.com', '%');
16SELECT * FROM `wp_2_postmeta` WHERE `meta_value` LIKE CONCAT('%', 'old.siteurl.com', '%');
1-- replace old URL with new URL
2UPDATE `wp_blogs` SET `domain` = REPLACE(domain, 'www.oldurl.com', 'www.newurl.com');-- must NOT have http:// or a trailing slash
3UPDATE `wp_site` SET `domain` = REPLACE(domain, 'www.oldurl.com', 'www.newurl.com'); -- must NOT have http:// or a trailing slash
4UPDATE `wp_options` SET `option_value` = REPLACE(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';
5UPDATE `wp_posts` SET `guid` = REPLACE(guid, 'http://www.oldurl','http://www.newurl');
6UPDATE `wp_posts` SET `post_content` = REPLACE(post_content, 'http://www.oldurl', 'http://www.newurl');
7UPDATE `wp_postmeta` SET `meta_value` = REPLACE(meta_value,'http://www.oldurl','http://www.newurl');
guid
in wp_posts
is kind of like permalink, mentions the entire site URL. Consequently, the results for guid
will be a lot more than post_content
which is checking for links inside the post content itself. (7457 vs. 253)guid
is NOT advised because doing so will mess up feed readers and show read items as new content again.You also need to check for directory paths if you have changed them during the migration. For example /var/www/html/wp-content/
vs. /var/www/mysite.com/public_html/wp-content/
1-- Main domain site
2UPDATE wp_options SET option_value = REPLACE(option_value, '/var/www/html/wp-content/', '/var/www/mysite.com/public_html/wp-content/');
3
4-- Additional sites
5UPDATE wp_2_options SET option_value = REPLACE(option_value, '/var/www/html/wp-content/', '/var/www/mysite.com/public_html/wp-content/');
wp-config.php
Update the values for WP_HOME
, WP_SITEURL
and DOMAIN_CURRENT_SITE
1// wp-config.php
2
3define( 'WP_HOME', 'http://example.com' ); // <-- change this
4define( 'WP_SITEURL', 'http://example.com' ); // <-- change this
5
6define('WP_ALLOW_MULTISITE', true);
7define( 'MULTISITE', true );
8define( 'SUBDOMAIN_INSTALL', true );
9$base = '/';
10define( 'DOMAIN_CURRENT_SITE', 'old.siteurl.com' ); // <-- change this
11define( 'PATH_CURRENT_SITE', '/' );
12define( 'SITE_ID_CURRENT_SITE', 1 );
13define( 'BLOG_ID_CURRENT_SITE', 1 );