How to exclude subdomains from WordPress Multisite

Ralph J. Smit Laravel Software Engineer

I love WordPress Multisite. It allows you to get a new WordPress site up and running within minutes. Especially if you're a developer and want to test a new theme (version) on a plain installation, this is really handy. Or if you are a company and you need a new site, e.g. for a project.

WordPress Multisite works with both subfolders and subdomains. Subfolders are sites created at domain.com/newsiteslug and subdomains are subdomain.domain.com. Setting up a multisite is – generally spoken – easy, though the subdomain version is a little bit more tricky.

Excluding a subdomain from WordPress Multisite only requires a simple RewriteRule in the .htaccess file.

How to exclude a subdomain from WordPress Multisite

Open up your .htaccess file. Since you already have a Multisite installation, the .htaccess should be in your main site folder, because WordPress Multisite requires it. If you open it, you can add a custom rewrite rule.

<IfModule mod_rewrite.c>
RewriteEngine on
 
RewriteCond %{HTTP_HOST} subdomain.ralphjsmit.com
RewriteCond %{REQUEST_URI} !subdomain/
RewriteRule ^(.*)$ subdomain/$1 [L]
 
</IfModule>

All you need to do is adding a simple snippet of code, before the other WordPress RewriteRules apply. Here's an example of excluding two (fictional) sites subdomain.ralphjsmit.com and subdomain2.ralphjsmit.com from WordPress Multisite. Make sure to place it before the WordPress part.

<IfModule mod_rewrite.c>
RewriteEngine on
 
RewriteCond %{HTTP_HOST} subdomain.ralphjsmit.com
RewriteCond %{REQUEST_URI} !subdomain/
RewriteRule ^(.*)$ subdomain/$1 [L]
 
RewriteCond %{HTTP_HOST} subdomain2.ralphjsmit.com
RewriteCond %{REQUEST_URI} !subdomain2/
RewriteRule ^(.*)$ subdomain2/$1 [L]
 
</IfModule>

Excluding a subdomain is really as simple as this! Remember to update the reference in all three lines per subdomain, otherwise things might not work as expected.

Published by Ralph J. Smit on in Wordpress-multisite . Last updated on 10 March 2022 .