IMPORTANT – TAKE A BACKUP OF THE SITES DATABASE BEFORE ACTIONING THE BELOW
The following will guide you to getting a WordPress multi-site deployed to staging or live.
Make sure that you have the follwing plugin installed.
WP Migrate DB – https://en-au.wordpress.org/plugins/wp-migrate-db/
When installed and activated. Head over to Network Admin -> Settings -> Migrate DB
For the settings:
- Keep Export File and checkboxes all checked
- Make sure Find & Replace is unchecked otherwise it will find and replace in the currents site DB. It will break the site.
- Expand Advanced options and uncheck Replace GUID’s
For the find and replace. the first will be prefilled based on where you are exporting from. You want to then enter in the first replace input box the new url. In this instance it was //www.cuc.edu.au its important that all websites home URL is set to www. Non-www is usually reserved for emails.
Second Find and Replace is the servers file location. This you only need to do once. First will be prefilled automatically. In the above instance the new file path will be /home/cucedu/public_html
When you are happy click export and then create a new database and then upload this database up.
Make sure htaccess is the same as when it was set up locally, it should be similar to this below.
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
Also make sure to copy multi-site configuration made in wp-config locally and make edits to the “Domain_current_site” to be the new sites domain.
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'cuc.edu.au');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
// define( 'COOKIE_DOMAIN', '' );
define( 'ADMIN_COOKIE_PATH', '/' );
define( 'COOKIEPATH', '/' );
define( 'SITECOOKIEPATH', '/' );
Now with multi-sites you may face the following issue. Say one of the multi-sites the home address is www.cucfarwest.edu.au and you enter cucfarwest.edu.au. You will always be redirected back to the main sites domain which in our case was www.cuc.edu.au. If you are facing this, make sure to add this to the top of WordPresses .htaccess after RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [L,R=301]
