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.
157 COMMENTS
Oldest
12 years ago
Hi, thanks so much for this, its been so helpful and I am so close to solving my multisite problems. I have followed everything you wrote and managed to get my second site to work as a subdirectory (/dj/), I can add pages in the admin, but when I come to view them it throws a 404.
Basically I am trying to view “http://quirksmode.dev/dj/” and my error is saying “You tried going to http://quirksmode.dev/dj/dj/ and it doesn’t exist.”
For some reason it is duplicating /dj/ do you have any ideas how I may solve this?
0
Reply
12 years ago
It’s all good, I fixed it. I had a remove category base plugin that needed to be disabled and reactivated to kick in. Thanks so much, you are a legend!!
One last thing, I don’t suppose you know a plugin that allows me to move posts/pages from one site to another within my network?
0
Reply
Author
Reply to David
12 years ago
Hello David, glad to hear you resolved your problem. I don’t know of a specific plugin that’ll allow you to directly transfer a post or page from one site to another within your network but I do know you can export posts and pages from one site to another via a WordPress export file. Visit Tools>Export in your Dashboard to learn more about it. I recently read on the WordPress support forum that the ability to move posts and pages directly between sites without downloading and uploading export files is a commonly requested feature; maybe the WordPress developers will put it into the next version.
0
Reply
Author
Reply to David
12 years ago
David, I think I have a plugin you might be interested in:
I haven’t tried it. It’s supposed to do as you want to do. Whether or not it does is another matter. I read about it here.
Have fun 🙂
0
Reply
12 years ago
Nice article Dion. I am planning to create new channels of my blog and right now, utilizing the multi-site feature of WP 3.0 seems to be the best way out, except for one snag – Google XML Sitemaps plugin doesn’t work in that mode. And it is quite an important plugin as far as I know.
I did search for alternatives, finally found one called XMl sitemap feed, something like that…but that didn’t work as expected. It gave errors and all.
So, that is what is stopping me from enabling the multi-site feature. Can you help?
Thanks,
Abhijeet
0
Reply
Reply to Abhijeet Mukherjee
12 years ago
In fact I just saw that you are using the same plugin I was talking about. And it appears to have the same issue – https://journalxtra.com/sitemap.xml gives errors when I try to load it.
0
Reply
Author
Reply to Abhijeet Mukherjee
12 years ago
LOL, I see what you mean. Try viewing it in a different browser – sitemaps aren’t supposed to be viewable by web browsers so sometimes they load in them and sometimes they do not. the important point is whether they are readable by bots. As far as I’m aware mine is (was the last time I checked). I’ll recheck in a minute and post back.
0
Reply
Author
Reply to Abhijeet Mukherjee
12 years ago
Hello Abhijeet, XML Sitemap Feed does work. It had a few issues initially when Multi Site was first released but there have been a few updates since. Retry it and remember that it produces a virtual sitemap so move the old sitemap from your blog’s root directory (rename it) and use the KB robots.txt plugin to direct search engines to your new sitemaps (add something similar to “Sitemap: https://journalxtra.com/sitemap.xml” to your virtual robots.txt file (no quotes)).
I suggest the kb robots.txt plugin because each virtual site requires its own robots.txt file and the best way to create one is to use the plugin to serve them when called by bots.
Also, the sitemap address can sometimes be a variation of your sites usual address prefix e.g. http://www.site.tld/sitemap.xml OR http://www.site.tld/sitemap.xml OR http://site.tld/sitemap.xml . One of them will work, it’s just a case of using trial and error to establish your sitemaps’ address.
Good luck with your sites and post back if you need any help.
0
Reply
Reply to Lee Hodson
12 years ago
Here’s a thread I posted on WP support forum – http://wordpress.org/support/topic/xml-sitemap-feed-plugin-problems ..check what the plugin author has to say about caching and all. I gave your site as the example there. 🙂
I use Robots Meta plugin already. Should I still go for KB robots.txt? And are you sure that each new site would need it’s own robots.txt? I was told by someone, who owns a huge blog with different channels, that he only has one robots.txt but different sitemaps. Although, he uses sub-directories and has separate WP installations in them. So I thought it should be more or less the same in WP sub-directory multi-site structure too…one robots.txt and different sitemaps…doesn’t work that way?
0
Reply
Author
Reply to Abhijeet Mukherjee
12 years ago
I’ve just looked at and replied to that thread. Google accepts the sitemap. I’ve just re-submitted it to double check it.
Regarding robots.txt, robots.txt is read by bots if encounted in subdomain and root directories but is ignored if encountered in subdirectories. If you use subdomain sites and want to specify different rules per site (e.g. for sitemap locations) then you will need a plugin to control the output of each site’s robots.txt file which is dynamically created by WordPress when requested by bots. Two other ways to direct search engines to your sitemaps are, 1, add a link to it in the footer of your websites and, 2, submit each site’s sitemap location to individual search engines (e.g Google’s Webmaster Tools, Bing’s Webmaster Tools).
The reason I use KB Robots.txt is that I know it works with Multi Sites. If you know that your current robots plugin works with Multi Site then stick with it.
0
Reply
Reply to Lee Hodson
12 years ago
So that means, since I’d be using sub-domains, I don’t need to worry about robots.txt, right? ( and yes, Robots meta does work in multi-site mode..I guess I just need to network activate it).
I cannot see your reply on that thread for some reason. Hence I’ll ask you here. Do you use W3 total cache? Did you configure it separately for each of the new blogs you added?
Another question – did you a notice significant changes in your search traffic after you shifted to the xml sitemap feed plugin? I just wanna be absolutely sure before I shift to that sitemap plugin. Google’s so important you know. 😉
0
Reply
Author
Reply to Abhijeet Mukherjee
12 years ago
If you install your sites in subdomains you will need a robots.txt file for each site; if you install your sites in subdirectories you will (as far as I know) not need a robots.txt for each site. I usually create them for all my sites, just in case. I do use W3 Total Cache. I did configure it separately for each site. The plugin’s Multi Site version is awkward to set-up because it doesn’t automatically create the directories it requires to store cached files; also, it doesn’t automatically edit the .htaccess file. It is also the caching plugin recommended by Hostgator (my preferred host). I didn’t notice any drop in traffic after installing XML Sitemap Feed. You might be surprised but JournalXtra only gets between 400 and 500 unique visitors per day. Sometimes only 300. Most of my traffic comes from Google (98%, at a guess). Most of the rest comes from backlinks, Bing then obscure search engines followed by Yahoo and Ask. Never really ranked well with Yahoo, bing and Ask. I really don’t know why. Compete and Alexa tell a different story but their figures are made up, ahem (cough, cough), I mean extrapolated from stats collected from the browser’s of surfers who have particular plugins installed that track their surfing habits. Sitemaps aren’t really necessary unless your site is poorly set-up. Provided you link into your site and every page is linked into from other pages within your site then you shouldn’t really require a sitemap. the only reason I use sitemaps is… Read more »
0
Reply
Author
Reply to Lee Hodson
12 years ago
Just to let you know, WordPress MS creates a separate virtual robots.txt file for each site it serves. Remember that when you use a plugin that creates a virtual robots.txt or sitemap.xml for each of your sites you must not have a non-virtual sitemap.xml or robots.txt file stored in your root site’s (or other sites’) root directory.
0
Reply
12 years ago
Ah, Dion, I am confused again. 🙂 Could you please check out that WP thread again – http://wordpress.org/support/topic/xml-sitemap-feed-plugin-problems , especially the conversations I had with RavanH towards the end.
I basically need to know what are the steps I should follow. Here’s my current position – I have a WP blog, WP version 3.0, it has a manually created robots.txt and a sitemap.xml created by the google xml sitemap plugin.
Now, I need to enable multi-site mode and add 1 or 2 blogs in sub-directories. Since google xml sitemap plugin doesn’t work in that mode, I need to ensure that I find something else.
So here’s what I am gonna do.
1. I’ll activate WP multi-site.
2. I’ll make sure it accepts sub-directories by following the tutorial given by you in this article.
3. I’ll remove google xml sitemaps plugin, and also remove any sitemap.xml file in the root directory.
4. I’ll install and activate the xml sitemap feed plugin.
5. I’ll go to the robots.txt file in the root directory, which I had from the very beginning, and add references to sitemaps for the new sites at the end (as suggested by RavanH)
So, those are the steps I’ll follow. Now you gotta tell me if everything’s alright in the above steps. Do check that WP support forum thread too. 🙂
0
Reply
Author
Reply to Abhijeet Mukherjee
12 years ago
Hello again, I wondered when you’d post back. I understand your confusion. The steps you have outlined are the ones I would follow. RavanH knows more about sitemaps than I do and his suggestion seems to concur with those provided at Sitemaps.org.
Because you are using sub-directories instead of sub-domains, RavanH suggests you reference each of your sitemaps in your robots.txt file by adding a line similar to
Sitemap: http://www.example.com/sitemap.xml
to the end of your non-virtual robots.txt file for every sitemap you have.
As a further example, if you have three sites then you should add three references to sitemaps to the end of your non-virtual (real/physical) robots.txt file:
Sitemap: http://www.example.com/sitemap.xml
Sitemap: http://www.example.com/sub-directory-site-one/sitemap.xml
Sitemap: http://www.example.com/sub-directory-site-two/sitemap.xml
Hope that helps.
A little warning here: if your sites attract lots of visitors, are server resource hungry and you use a shared server then WordPress MS might not be the right option for you because one site’s over usage might result in all sites being put out of action by your host suspending your single WordPress MS index.php script. At least with non MS sites, all sites have an individual root index.php script and if one is suspended then it affects only the site it belongs to.
0
Reply
12 years ago
OK, cool. So we now have both the experts (you and RavanH) on the same page, and I know exactly the steps I need to follow. Good. 🙂
Yeah, I am on a shared server, but the traffic isn’t that much. The site is only 6 months old. Plus I am planning to move to VPS next month anyway. So I think it’d shouldn’t be a problem. But thanks for informing me.
Thanks again Dion for your prompt replies. Really appreciate it. I’ll report back when I have the process done, which I think should be this weekend.
0
Reply
Author
Reply to Abhijeet Mukherjee
12 years ago
You’re welcome. I look forward to hearing how you get on.
0
Reply
12 years ago
Works excellent , thanks you really very much , I can’t imagine how many days I should spent to resolve this problem without you. Gotta say that I have changed the subdomain installation to subdirectory (so NO new fresh installation ) and this thing seems that works too.
0
Reply
Author
Reply to Daniel
12 years ago
You’re very welcome Danial. Remember to bookmark JournalXtra for when you have other WordPress needs 🙂
0
Reply
dianat
12 years ago
Thanks for this post. Works like a charm.
0
Reply
Author
Reply to dianat
12 years ago
You’re welcome.
0
Reply
Dave Harris
12 years ago
This page:
http://codex.wordpress.org/Create_A_Network
says:
“You cannot choose Sub-directory Install in the following cases:
* If your existing WordPress installation has been set up for more than a month, due to issues with existing permalinks. (This problem will be fixed in a future version.) ”
Does the above this this issue? Or can I still not transition my current set of individual WP blogs (using subdirectories) to WP 3.x multisite, using subdirectories? I would love to move to WP MS if this issue has been fixed by the above code (it’s not clear to me).
Thanks, this is a great tutorial in any case!
0
Reply
Author
Reply to Dave Harris
12 years ago
The above guide addresses that issue so, yes, you will be able to force WordPress to use subdirectories with the above guide. Be careful before migrating to WordPress MS. If your sites are CPU/memory hungry and you’re on a shared server then WordPress MS might not be the right solution for you.
0
Reply
Dave Harris
Reply to Dave Harris
12 years ago
Cool, great to know. Thank you!!
0
Reply
12 years ago
Hi,
I was just working with a site that has this implemented and had broken somewhere along the way. Failing to find and fix the problem, we’ve implemented the whole network and forced subdirectories anew, and it almost all works except that the dashboards of all the sub-sites have no CSS or images (actually the sites themselves have no style from the Twenty Ten theme either). All the image and stylesheet URLs have the site slug in them rather than being located at the root of the network.
So they’re NETWORK_URL/site-slug/wp-admin/css… instead of NETWORK_URL/wp-admin/css…
Have you encountered this? Have you any idea how to fix it? You mentioned something that sounded similar to this in the post, but I’m pretty sure I used significantly unique URLs. I don’t believe that is the cause.
0
Reply
Author
Reply to kristarella
12 years ago
Hello Kristarella, welcome to JournalXtra.
I had the same issue until I implemented the second list of re-write rules stated in the post. The only suggestion I have is that you check your re-write rules. Possibly use a near blank .htaccess file with only the DirectoryIndex index.php line and the essential WordPress re-write rules stated above. Another possibility is that a plugin is interfering with the sites’ display. If neither the aforementioned work, try mirroring some of the network in a fresh WordPress installation in subdirectory (new database with a couple of sites exported to it) to see whether the issue persists.
Please let me know your solution if you resolve the issue some other way.
Re-reading the post I realised I had forgotten to mention the method for removing the ugly blog slug. I’ve edited it accordingly.
0
Reply
Hunter Gatherer
12 years ago
Hi,
Worked great on an “old” new site that we hadn’t posted content on yet. I’ll let you know when we try to migrate an existing one.
Thanks a lot for your guidance. The only thing I could add is that when you go to Tools>Network, that’s when it’s going to ask you to “Install”, with only the subdirectory option. After you hit “install”, that’s when you update your wp-config.php file and your .htaccess files to your given code.
I wasn’t sure whether to hit “install” when it only gave the subdirectory option. I went ahead and did, then was given the opportunity to do your suggested modifications.
Good work. Many, many thanks.
HG
0
Reply
Author
Reply to Hunter Gatherer
12 years ago
Hello Hunter Gatherer. I’m glad it worked for you. Thank you for pointing out the detail I missed. I’ll update the guide accordingly 🙂
0
Reply
12 years ago
After following these directions now all the posts/pages/etc. on my main site redirect to the main site’s index page. Any idea why this would happen?
0
Reply
Author
Reply to Dustin DeKoekkoek
12 years ago
I reckon you’re using the Redirection plugin. Go to Redirection>Groups>Modified Posts then delete all redirections that show as a forward slash (/) only. If not the redirection plugin then it’ll be something similar. Please post back with your results whether good or bad.
0
Reply
Reply to Dustin DeKoekkoek
12 years ago
Can’t seem to find anyone else having this issue. I “deactivated” multisite for now until I can find a solution.
0
Reply
Reply to Dustin DeKoekkoek
12 years ago
I do have that plugin but I had it disabled. The problem specifically happens after modifying wp-config.
0
Reply
Reply to Dustin DeKoekkoek
12 years ago
It’s a 302 redirect. Still trying to figure out why.
0
Reply
Reply to Dustin DeKoekkoek
12 years ago
I have found the problem to be when changing
define( ‘SUBDOMAIN_INSTALL’, true );
to
define( ‘SUBDOMAIN_INSTALL’, false );
I can go through the steps perfectly but when I change this value to ‘false’ every page http://MLTnews.com/* is redirected back to http://MLTnews.com. When I change the value back to ‘true’ it does not redirect.
Any ideas?
0
Reply
Author
Reply to Dustin DeKoekkoek
12 years ago
I’m just about to goto sleep. I’ll quickly reply before I do. It is a strange problem you’re having.
I would reactivate the Redirection plugin and make the changes I showed earlier. Even try your site with as near empty an .htaccess file as possible. If you use DirectoryIndex index.php then leave that as the sole line in it. Remember to back up your.htaccess file before editing it.
If none of the above help it will be a process of elimination. I would start disabling and re-enabling plugins individually. If you’re not worried about disabling all plugins simultaneously then re-enabling them individually post testing for the error then I would do that.
0
Reply
12 years ago
The only other code in the .htaccess was for W3 Total Cache but I have deleted that temporarily for testing purposes here. I haven’t gone through and reactivated each plugin one by one but the redirection happens when all are deactivated as well as when all are activated.
I will try reactivating them one by one.
0
Reply
Author
Reply to Dustin DeKoekkoek
12 years ago
Temporarily change your permalinks to the WordPress default and see what happens. Backup your original settings so you can easily restore them after testing.
Also, use the contact form (see menu bar above) to send me a copy of the edits made to your wp-config file. Please do not send the whole document, I don’t need your database details 🙂
0
Reply
Reply to Dustin DeKoekkoek
12 years ago
I’ve found that the redirects don’t happen when I have it on default permalinks but if I change it to anything else it redirects. I’ve also been having a discussion in the WP.org forums here.
0
Reply
Author
Reply to Dustin DeKoekkoek
12 years ago
Hello Dustin, I’ll reply here as well as at wordPress.org for the benefit of others.
You said the /blog/ slug still shows in the backend. It will. That’s normal. It does this with my test blogs and with those I install for others.
I’m now stumped as to what to suggest. It’s good we’ve established it’s a permalink issue. But knowing how to fix it is something else. I’ve had a few problems with WP MS that have required me to re-install to get it functioning as it should (unrelated to forcing sub-directories). Those problems were created by plugins. Maybe that’s what you’ll have to do. We’ve tried disabling and re-enabling plugins, we’ve checked the redirects created by the Redirection plugin (removed root / redirects) and you’ve used an .htaccess file with only the essential rules.
Maybe the .htaccess WordPress re-write rules are wrong. Here’s a copy of the .htaccess rules used on one of my subdirectory using WP MS sites:
DirectoryIndex index.php
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]
Try the above .htaccess file and see what happens. It’s possible there’s a mistake in the rules you are using.
0
Reply
Ken
Reply to Lee Hodson
11 years ago
hey thank! had similar isssues,and while the first htaccess post didnt work, THIS one did.
ty ty ty ty. I cant thank you enough.
0
Reply
Reply to Dustin DeKoekkoek
12 years ago
I’m in agreement with you that I tried all the things you mentioned above.
No luck on that new .htaccess. Same results. I’m moving towards backing up/exporting my current WP installation (around 1,000 posts), doing a fresh install and then importing all the posts/pages after I set up multisite.
0
Reply
Author
Reply to Dustin DeKoekkoek
12 years ago
Just a question Dustin, do any of your post titles conflict with you subdomain names?
Backing up and re-installing can be a tedious job. It’s not always perfect either. Have you done it before?
Given your current problem, I wouldn’t use the original database. I’d keep it so I could export components of it e.g. the tables for certain plugins.
0
Reply
Reply to Dustin DeKoekkoek
12 years ago
I hadn’t even made any additional sites on the network yet. Just the main one.
0
Reply
Author
Reply to Dustin DeKoekkoek
12 years ago
Does your hosting plan allow addon domains? If so, I can point one of the domain names I use for test sites toward your server so you can create a mirror of MLTnews to test that re-installation will fix it. If you want to do this, join me on Facebook and I’ll set it up. It’s easier that way than by posting multiple comments here. Attention other readers: I’ll write up the solution for others once one is found. My Facebook profile ID is http://www.facebook.com/DionDeVille
source : https://journalxtra.com/wordpress/how-to-force-multi-site-to-use-subdirectories/