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 responses to “Changing WordPress Mu from Subdomains to Subdirectories”

  1. adamwulf

    convert subdomain WordPress Mu install to use sub/directories/ instead: http://tinyurl.com/ctoomg

    This comment was originally posted on Twitter

  2. mlane

    Changing WordPress Mu from Subdomains to Subdirectories – http://bit.ly/Yrlko

    This comment was originally posted on Twitter

  3. Cambiar Wordpress MU de subdominios a subdirectorios | Codigo Geek

    [...] en subdominios, no podremos cambiarlo luego a subdirectorios si no es reinstalando. Pero en éste blog publican un tutorial que muestra una forma “no oficial” de hacerlo y parece terminar [...]

  4. DarklgWeb

    Changing WordPress Mu from Subdomains to Subdirectories http://minurl.fr/fdw

    This comment was originally posted on Twitter

  5. 465media

    Changing WordPress Mu from Subdomains to Subdirectories http://ow.ly/5DAj #wordpress

    This comment was originally posted on Twitter

  6. Andrea_R

    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.

  7. ariyo

    Changing WordPress Mu from Subdomains to Subdirectories http://tr.im/kNzB

    This comment was originally posted on Twitter

  8. JAC2

    This is EXACTLY what I was looking for the other day. Thanks! :-)

  9. ivan

    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!!!

  10. BuddyPress Links #7 · Buddypress Links

    [...] How to change WordPress Mu from subdomains to subdirectories [...]

  11. Inderjeet Singh

    I was looking for this for my fresh Buddypress+Mu install. Hope the plugin for this releases soon

  12. Teleflux

    This was helpful, however, I didn’t have to edit the httpd.conf

  13. Greg

    This was very helpful.

    Thanks alot!

  14. Anup

    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

  15. Eileen

    Thanks so much – this was exactly what I needed on my new install (I picked subdomains when I shouldn’t have!)

  16. Nik

    Thanks, solved my problems.

  17. Jason Bonham

    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.

  18. Ivan

    Would there be any hiccups if I reverse the process from subdirectories to subdomains?

  19. henrik hammer

    Just a note: it’s important to remember the trailing slash ‘/’ for the new subdirectory, when updating the settings in step2

  20. Jussi

    Thanks! This was just what the doctor ordered ;)

  21. Simeon Mus

    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

  22. Dwayne

    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

  23. Artful Dodger

    Hey, thanks very much for this post, worked perfectly without any hiccups, again, thanks a bunch.

  24. bloggista

    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. :-)

  25. TechieChic

    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”!

  26. Deryk Wenaus

    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

  27. Een jaar ervaring met WordPress MU [Wessel Zweers]

    [...] en de benodigde stappen worden bij mijn weten nergens op de officiële website uitgelegd (wel op particuliere blogs). Doorgaans wordt aangeraden om in deze situatie alles opnieuw te installeren. Verder heeft [...]

  28. fIlesonic

    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?

  29. From subdirectories to subdomains | RGVRockCity.com

    [...] wordpress.org forums – like here and here – I stopped at this post, Adam Wulf’s, Changing WordPress Mu from Subdomains to Subdirectories. Then it hit [...]

  30. Wordpress Blog Netzwerk auf Subdomain | i-mill

    [...] Subdirectory Network laufen. Eine Anleitung zur Umstellung von Subdomains auf Subdirectory gibt es hier.Fazit: WP benötigt im Multisite Modus saubere Serveraliasnamen, die auch als Subdomain im DNS [...]

  31. Speaking Agent

    This ALMOST worked for me… The theme on the new subdirectory site is not loading.

    also, i am unable to login under “…domainname.subdirectory/wp-admin”

    any thoughts?

  32. Coeurmechante

    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/

  33. Toz

    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

  34. Toz

    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

Google Author link