How To Force WordPress Multi-Site to Use Subdirectories Instead of Subdomains

I was trying to run WordPress multi-site from a subdomain today and ran into an issue where WordPress wants to force me to use subdomains for my url structure.  So, my sites would look like “site1.subdomain.maindomain.com” rather than my preference of “subdomain.maindomain.com/site1”.

To fix this, I implimented the fix found here.

Specifically, in wp-config.php I needed to change

define( 'SUBDOMAIN_INSTALL', true );

to

define( 'SUBDOMAIN_INSTALL', false );

and replace my .htaccess file’s content with the following:

# 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

Pretty nifty!

p.s. You might will need to update your permalinks after making the changes above. (Thanks, Andrea!)

Posted in ,

Toby Cryns

Toby Cryns is a freelance CTO, expert WordPress consultant, and teacher.

He offers free advice to improve your freelance biz.

He also publishes small droppings every now and then to twitter.com/tobycryns and twitter.com/themightymo

Follow Toby's contributions on Github and WP.org.