Set up WordPress Multisite

·

·

A WordPress Multisite is an installation that shares the same files, and that generates different tables according to the different installations and that therefore, shares functionalities between them.

It is a very smart solution for certain needs such as multi-language sites (like this), multi-country, division of functionalities to make the main site less heavy.

This is because we can create/install plugins for our different installations. It may be the circumstance that we activate an entire online store on a subsite in order to maintain maximum performance in the main portal. This type of installation usually occurs in very large sites.

This guide is a collection of different sites to be able to install the multisite with the two configurations: subdomains and subfolders. The subdomains option can also be used in multidomain configuration. It will only be necessary once a subdomain has been created, to change the direction to the final one.

The main site is the official WordPress HandBook, which the first thing it tells us is to paste this line into the wp-config file.php:

define( 'WP_ALLOW_MULTISITE', true );

This will enable a new menu in Tools > Network Administration.

Configuring subfolders

Configuration in wp-config

define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'dominio.com');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

Configuration in htaccess

# BEGIN WordPress Multisite SUBFOLDER
<IfModule mod_rewrite.c>
RewriteEngine On
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]
</IfModule>

Configuration with subdomains

define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', true);
define('DOMAIN_CURRENT_SITE', 'dominio.com');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

Htaccess if it is a subdomain

# BEGIN WordPress Multisite SUBDOMAIN
<IfModule mod_rewrite.c>
RewriteEngine On
 RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
 RewriteBase /
 RewriteRule ^index.php$ - [L]
 add a trailing slash to /wp-admin
 RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
 RewriteCond %{REQUEST_FILENAME} -f [OR]
 RewriteCond %{REQUEST_FILENAME} -d
 RewriteRule ^ - [L]
 RewriteRule ^(wp-(content|admin|includes).) $1 [L] RewriteRule ^(..php)$ $1 [L]
 RewriteRule . index.php [L]
</IfModule>

And another important thing for multisite, is that if we make a mistake with the address and put www or without www, it will be redirected to a registration page of the new site. This is rarely used, so we are interested in disabling it, adding this code in wp-config:

define( 'NOBLOGREDIRECT', 'https://dominio.com' );

Cookie settings for multidomain

If you want the option of multidomain, this is dominio.com, dominio.es, etc. so that there are no problems with cookies, you must add these lines in wp-config:

define('ADMIN_COOKIE_PATH', '/');
define('COOKIE_DOMAIN', '');
define('COOKIEPATH', '');

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.