Home SEO How to Use WordPress Multisite for Subdomains and Subdirectories both?

How to Use WordPress Multisite for Subdomains and Subdirectories both?

by Umair Hashmi
1.9k views
How to Use WordPress Multisite for Subdomains & Subdirectories both?

Today, I am going to explain that how can we use WordPress for Subdomains and Subdirectories.

Wordpress Multisite only offers either subdomains or subdirectories. Sometimes we want to use subdomain and subdirectories both.

I realized this problem while I was transferring my blog from subdomain to subdirectory. However, I already had another subdomain on my multisite. I wanted to use WordPress Multisite for my subdomain and subdirectory both. Wordpress only allows us to select any one of them.

Why did I move my blog from subdomain to subdirectory?

As I am talking about WordPress Multisite subdomains and subdirectories, I want to add one more thing that why I migrated my blog on my subdirectory.

There is a debate, some experts say blogs should be on subdirectory and some say it should be on a subdomain.

The simple answer for me is, Google considers subdomain as a separate website and subdirectory as a part of a website.

Blogs generate a lot of traffic to the root website. Therefore, I migrated my blog on Wordpress Multisite from the subdomain to a subdirectory.

What is the difference between subdomain and subdirectory?

After searching a lot of articles I understood the main difference of Subdomains and Subdirectories.

Subdomain considers as a separate website and it does not help in SEO for the root domain website. Subdirectory considers as a part of the root domain and it helps in SEO for the root domain website

If you have a WordPress Multisite or any other website which offers product and services in different countries, you need to go for a subdomain.

One more thing, don’t worry about the duplicate content for regional subdomains or websites. You just need to make sure that your website is optimized according to International SEO.

Steps to make WordPress Multisite for Subdomains and Subdirectories

As I mentioned above I moved my blog from subdomain to subdirectory. So, the given below steps will help if you already have multisite as a subdomain and want to move/add subdirectory now.

Update wp-config file

Go to your wp-config file. Copy the below code and update your code.

define('WP_DEBUG', false);
define('WP_ALLOW_MULTISITE', true);
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'www.yourdomain.com');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
define( 'ADMIN_COOKIE_PATH', '/' );
define( 'COOKIEPATH', '' );
define( 'SITECOOKIEPATH', '' );
define( 'NOBLOGREDIRECT', 'http://www.yourdomain.com' );

Update .htaccess file

Find the # Begin Wordpress and # End Wordpress in htaccess file. Copy the below code and replace it in your file.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [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>
# END WordPress

The site address in the multisite network admin

Go to your Network admin and select a site that you want to migrate from subdomain to subdirectory and update the site address (URL)

Update the URLs

Updating the URL is the most important part when you migrate WordPress multisite from subdomain to a subdirectory.

I would recommend first make a backup of your database. There is a nice plugin that can do this job easily.

Download this plugin: Search & Replace By Inpsyde GmbH

This plugin allows you to make a backup before doing anything with your database.

First, you need to do is to create a backup of your database then replace the subdomain URL with the subdirectory URL by search and replace feature.

Read the instruction carefully on the plugin site and then apply and changes.

Add 301 redirect

The final step to create 301 redirections from your old site to the new site. Add the below code in your .htaccess file and update it with your site URL.

# BEGIN Subdomain Migration
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain\.yourdomain\.com
RewriteRule ^(.*)$ https://www.yourdomain.net/subdirectory/$1 [R=301,L]
</IfModule>
# END Subdomain Migration

The above code will create a redirection for all of your subdomain pages. It would help in SEO as well.

Done!

If you have applied above instructions then I am sure you have successfully migrated your Wordpress Multisite from a subdomain to subdirectory.

Let me know in the comments if you have any questions about it.

You may also like

Leave a Comment

13 − eight =