In a project I was working on WordPress multisites run on subdomains and we wanted to change multisite subdomains to subdirectory path like this: www.test.domain.com to www.domain.com/test.
Following steps are needed to follow for converting the subdomain to subdirectory URL :
1. Firstly we add the subdirectory path instead of subdomain path or we can say edit the site url in wordpress network admin like this :

2. Then make the changes in the Multi Site’s URL rewrite rules. For that we edit the .htaccess file.
.htaccess file code could be like this :
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
# uploaded files
RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.php [L]
Change the existing code to :
# BEGIN WordPress
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).*) $1 [L]
RewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
# END WordPress
These simple steps help us to convert the subdomain into subdirectory path.

One comment