One of the most common issues to afflict most web developers who try to enable WordPress Multi Site is WordPress’s insistence that subdirectory blogs cannot be setup. The message WordPress throws up to show its dominance over afflicted web developers is:
Because your install is not new, the sites in your WordPress network must use sub-domains. The main site in a sub-directory install will need to use a modified permalink structure, potentially breaking existing links.
And the first thing afflicted web developers do is… they scream at their computers “What the f**k is that supposed to mean?”
Seriously, what is it supposed to mean?
The next thing they do is Google for answers. I know this because I tried both strategies before I bit the bullet and re-installed a very large WordPress installation. Some of my search terms were:
- Can’t enable multi site subdomains
- WordPress won’t allow subdomains
- How do I enable subdomains not subdirectories in WordPress
- How do I force subdomain use in WordPress MS
- WordPress subdomain subdirectory installation problem multi site
If you followed the same path as me and eventually, after re-installing WordPress, returned to the Multi Site activation screen you would know that re-installation, contrary to what is indicated by WordPress’s message, is not the solution. No, what WordPress is trying to say in a convoluted way is not that the WordPress installation is too old for Multi Site to be enabled for subdirectories but something else. Here is a translation of its message:
The URLs of some of your blog posts might conflict with the URLs of the subdirectory sites you create when Multi Ste is enabled therefore it is advised that you do not enable subdirectory sites.
Why the hell the WordPress development team use such cryptic error messages that require translation is, well, a Universal mystery.
In short, if a WordPress site is more than 30 days old, WordPress will try to prevent its multi-site conversion from using subdirectory addon sites.
There is a workaround to enforced subdomain addon site installations. Yes, we can fight back and force WordPress to allow subdirectory sites.
Force WordPress to Allow Subdirectory Blogs
During the activation of Multi Site a few lines of code need to be added to wp-confg.php. One of those lines states:
define( 'SUBDOMAIN_INSTALL', true );
That line tells WordPress to use subdomain addon sites.
Change it to
define( 'SUBDOMAIN_INSTALL', false );
and you will now be able to create subdirectory sites.
Currently, WordPress messes around with subdirectory site URLs. It adds a /blog/ slug after the TLD. For example, if a subdirectory site is created with the name “apple” such that its URL should be
http://domain.tld/apple
then WordPress renames it
http://domain.tld/blog/apple
Now that does not look very professional. In fact, it looks pretty damn ugly. Thankfully, the “blog” slug can be removed. A plugin is available from ThinkingWordPress (direct link) which does just that – it removes the ugly “blog” slug.
There are Two Snags with All This
Forcing WordPress to allow subdirectory addon sites on old WordPress installations has a price:
- Subdirectory sites that resemble existent post, page, tag, category or directory names must not be created,
- Some subdirectory sites will not display as they should because of conflicts with the main site’s permalink URL structure.
The solution for the first issue is simple:
- Do not create addon sites with names the same as existent WordPress slugs.
The second problem is characterized by any of
- Subdirectory sites do not display when viewed
- Subdirectory sites display but their themes are corrupt (missing CSS files)
- Subdirectory site backend admin panels redirect to the main site’s admin panel
Other symptoms will probably exist also.
The solution is simple and involves changing the Multi Site’s URL rewrite rules.
Edit your .htaccess file and replace
# 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] # END WordPress
With
# 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).*) $1 [L] RewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L] RewriteRule . index.php [L] </IfModule> # END WordPress
And that is all there is to forcing WordPress to allow subdirectory addon site installations when Multi Site is enabled.
The Blog Slug
WordPress will insist on inserting a blog slug into the sub-directory URLs such that my-blog.tld/site-one/my-post will look like my-blog.tld/blog/site-one/my-post. This can be removed with the Remove Blog Slug plugin from here.