Changing WordPress Mu from Subdomains to Subdirectories

When you install WordPress Mu, it warns you:

Please choose whether you would like blogs for the WordPress ยต install to use sub-domains or sub-directories. You can not change this later. We recommend sub-domains.

It’s true there’s no documented way to change this setting, and the current advice is to reinstall (!), but I aim to change that. Instead of reinstalling plugins, reconfiguring plugins, and then powering through the nightmare that is WordPress export->import, I resolved to find whatever setting was buried in WordPress and do it manually. And lucky for me, it turned out to be surprisingly easy.

I’d originally set up welcome.totheinter.net to use subdomains for my Mu installation, but I decided recently that subdirectories would make much more sense. After all, I’m using Mu to power my one site, and subdomains feel like lots of separate sites. In retrospect, installing Mu as subdomains was the wrong decision.

So during some downtime in the ‘ole ICU last month, I decided to see if this weren’t, in fact, a solvable problem, and it turns out it’s a pretty easy fix.

Step 1: Backup your database and config file

I’ve always subscribed to the “protect my data from my #1 enemy: me!” mentality.

Step 2: change each blog’s URL

In the admin console, go to the blogs page.

Blogs section

For each blog, click the edit link to edit that blog’s details. You’ll want to edit the following fields to all be consistent with the new location you want each blog:

  • Domain
  • Path
  • Siteurl
  • Home
  • Fileupload Url

For instance, I used to have one of my blogs set up at http://page2.welcome.totheinter.net/ but I moved it to http://welcome.totheinter.net/notes/. To do that, I changed the Domain from “page2.welcome.totheinter.net” to just “welcome.totheinter.net” and the Siteurl from just “/” to “/notes/”. I similarly updated all of the other fields for that blog.

Step 3: Update wp-config.php

There’s one line in the wordpress config file that tells Mu to use subdomains instead of subdirectories. Change:

define('VHOST', 'yes');

to:

define('VHOST', 'no');

Step 4: Update httpd.conf

If you’ve set up Mu to use subdomains, then you need to undo your wildcard subdomain setup in your httpd.conf. Mattย Mullenweg has a great post explaining how to create the wildcard domain in the conf, so if you’re trying to go from subdirectories to subdomains it’s a great read.

If you’re going from subdomains to subdirectories (like me), just remove the wildcard domain from your httpd.conf and restart apache.

Make sure (of course!) that you still have a virtual host defined for your actual site’s domain. It should look something like:

<VirtualHost 207.58.152.45:80>
ServerName welcome.totheinter.net
ServerAlias www.welcome.totheinter.net
DocumentRoot /home/internet/public_html/welcome
ServerAdmin webmaster@welcome.totheinter.net
UseCanonicalName Off
</VirtualHost>

Optional Step 5: Redirect from old subdomain to new subfolder

Good SEO tells you to redirect a URL you move to it’s new location with a 301 redirect header. To do that, I first setup a subdomain in CPanel that matched the blog’s old subdomain location. Then I just edited the .htaccess file for that subdomain to point all incoming traffic to the new URL. The .htaccess for page2.welcome.totheinter.net is now:


RewriteEngine On
RewriteBase /
RewriteRule ^(.*) http://welcome.totheinter.net/notes/$1 [R=301,QSA,L]

Conclusion

It turns out resetting WordPress Mu to use subdirectories instead of subdomains isn’t all that bad! And I’d imagine that moving from subdirectories to subdomains requires near identical steps.

Hope this helps you out – it’s certainly saved me from a reinstall hell! ๐Ÿ™‚

36 thoughts on “Changing WordPress Mu from Subdomains to Subdirectories

  1. Yep, that does work if you have only the main blog and maybe 1 or 2 blogs to burn through.

    Now imagine how fun that would be for someone with 300 blogs. ๐Ÿ™‚

    There *IS* a script available for this, but it is unreleased. It will be out there soon-ish though.

  2. true enough ๐Ÿ™‚ for the i-have-tons-of-blogs people it won’t won’t be terribly efficient, but it was a painless enough process that i can imagine doing it for a few tens of blogs easily enough.

    for the people who just can’t wait, hopefully this’ll tide people over till the script is released. ๐Ÿ™‚

  3. thanks so much!!!
    just had a fuckup with dreamhost, i dont wanna use their PS, so i decided to turn everything away.
    Thank you so much!!!

  4. Plz tell me whether its possible to have two instances of WPMU installed at the root – one working with subdirectory structure and the other working in subdomain structure?

    thanks

  5. Thankyou,

    very helpful information. My hosting service took care of the wild card part. You can always add that to the directions, so newbies like myself are aware of the potential option.

  6. Thank you for the article. It will help me very much.
    Andrea says “There *IS* a script available for this, but it is unreleased. It will be out there soon-ish though.”
    Is it released since then? Where can we find it, please?
    thanks

  7. This worked like a charm – I set it up with subdomains originally, thinking I’d convince godaddy to make it work, but I failed. I had just one blog to convert, quick and simple.
    thanks

  8. This is exactly what I need. Thanks for this valuable info. I’ve been long wanting to switch from subdomains to subdirectory but I was just kinda lazy to do a re-install. will try this one and hope it works. ๐Ÿ™‚

  9. Thank you so much! I had only just barely installed WordPress MU and had picked the wrong option and realized it as soon as I clicked the install button. Definitely nice to not have to start all over, since for me it was just a simple change in the wp-config from “yes” to “no”!

  10. very helpful!! someone should add this to the codex somethere. I’m going to add some keywords here that I searched on before I got here, just so other searcher may find this helpful post. SUBDOMAIN_INSTALL MULTISITE WP_ALLOW_MULTISITE DOMAIN_CURRENT_SITE

  11. What about using a seperate domain?

    IE: Main site is example.com

    I wanted to host testsite.com, but when I visit the blog and click any links it goes back to test.example.com, is there no way to hide that? Is the only option to install another copy of wordpress?

  12. Hiya,

    It almost worked for me too– the theme wasn’t loading (the header was looking for domain.com/subdirectory/path/to/theme instead of domain.com/path/to/themes. Also, I was getting 404 errors on wp-admin pages for my subdirectory blogs.

    For those staggering in, the directions here, plus the change to .htaccess in the link below fixed both problems (had to deactivate/reactivate theme):

    http://journalxtra.com/websiteadvice/wordpress/how-to-force-multi-site-to-use-subdirectories-2427/

  13. Thanks!! These instructions together with Coeurmechante’s htaccess changes, did it for me as I am changing a subdomain site to a subfolder site.

    I had to make sure to clean out my hosting account’s built-in cache, refresh my browser and right now everything is working. Saved me a few days work rebuilding a subdomain site as a subfolder site.

    To be sure, here’s that .htaccess setup, courtesy of Coeurmechante:

    # 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

  14. Another challenge for me was to move one of the former subdomain sites to show as the main site, in the root folder with no subdirectory. That proved easy as well:

    in /wp-admin/network/sites.php first rename the folder of your current root folder install (for example rename it to: /old/)

    then rename your subfolder install so that it now shows as the root folder /

Leave a Reply to Inderjeet Singh Cancel reply

Your email address will not be published. Required fields are marked *