Skip to content

Instantly share code, notes, and snippets.

@aamnah
Last active April 30, 2020 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aamnah/98a0c31bb9fc3fff27de00cf4c172c8d to your computer and use it in GitHub Desktop.
Save aamnah/98a0c31bb9fc3fff27de00cf4c172c8d to your computer and use it in GitHub Desktop.
Change WordPress Multisite Domain

Change WordPress Multisite Domain

You need to update five different tables in the database in order to change the domain, as well as updating the wp-config.php file

The following SQL script takes care of updating all tables in one go. Make sure to replace newdomain.com and olddomain.com (minus the http:// at the begining and / at the end) with the domain you want to change to before running the SQL commands

In wp-config.php, update the following line:

define( 'DOMAIN_CURRENT_SITE', 'newdomain.com' );
-- search and replace 'olddomain.com' and 'newdomain.com' below with your domain,
-- leave the 'http://' part and the trailing '/' at the end as is, do not replace it
-- wp_site & wp_blogs
-- can NOT have http://
-- can NOT have trailing slash
UPDATE `wp_site` SET `domain` = 'newdomain.com';
UPDATE `wp_blogs` SET `domain` = 'newdomain.com';
-- wp_options
-- MUST have http://
UPDATE `wp_options` SET `option_value`='http://newdomain.com' WHERE `option_name`='siteurl';
UPDATE `wp_options` SET `option_value`='http://newdomain.com' WHERE `option_name`='home';
-- wp_2_options
-- MUST have http://
UPDATE `wp_2_options` SET `option_value`= REPLACE(option_value, 'http://olddomain.com', 'http://newdomain.com') WHERE `option_name`='siteurl';
UPDATE `wp_2_options` SET `option_value`= REPLACE(option_value, 'http://olddomain.com', 'http://newdomain.com') WHERE `option_name`='home';
-- wp_sitemeta
-- MUST have http://
-- MUST have trailing slash
UPDATE `wp_sitemeta` SET `meta_value`='http://newdomain.com/' WHERE `meta_key`='siteurl';
-- WordPress has different rules for different fields.
-- The wp_site and wp_blogs tables can NOT have http:// or a trailing slash at the end of the domain name,
-- whereas in the wp_options table, it is required to have the http:// at the beginning.
-- In the wp_sitemeta table it is required to have http:// at the beginning and a trailing slash at the end.
-- reference: https://www.hostgator.com/help/article/how-to-change-a-wordpress-multisite-primary-domain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment