MU is virtually yours

One of the hardest, and ultimately neato-cool features of MU is the way it creates user’s blogs. On installation, you are given the choice of subdomains (username.domain.tld) or subdirectories (domain.tld/username/).

Either way, the site admin does not have to create subdomain or subdirectories for users. They exist only in the database. You will not find them on the server at all. I frequently see this question being asked in the forums from people who have accounts with subdomain limits. WPMU blogs don’t count towards that.

The options for this are stored in the database and are handled by Apache’s rewrite rules. Let’s have a look at how this is accomplished.

The first direction served up is within the httpd.conf file. Somewhere in there is a line like this:

ServerAlias domain.tld *.domain.tld

On a regular, non-virtual domain, the *.domain.tld won’t be there. This line above tells the system that anything.domain.tld is allowed, and that the system will answer requests for any subdomain. Also, in the DNS records a line like this will be there:

*.domain.tld. 14400 IN A your.server.IP.address.

This tells the system that this domain lives at this IP address.

Moving on, the rewrite rules live in the htaccess file. This directs file requests to their proper spots. The default htaccess file created on installation looks like this:

RewriteEngine On
RewriteBase /

#uploaded files
RewriteRule ^(.*/)?files/$ index.php [L]
RewriteRule ^(.*/)?files/(.*) wp-content/blogs.php?file=$2 [L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . – [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

The htaccess for subdirs is the same. Apache uses mod_rewrite to create URLs on the fly for the entries that exist in the database.

Now that Apache has handled the request for the blog, it lands on the folder where WPMU is installed. MU then looks up the blog information in the database, and serves it up.

[Post to Twitter] Tweet This Post 


bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark
tabs-top  banner ad


17 Responses to “MU is virtually yours”

  1. Peter - Antpeks says:

    and again this is a excellent tutorial on the sundomain features that are available for WPMU.

    thnaks Andrea

  2. yes, it is. thanks AR. chris

  3. Patrick says:

    can u help me with this? http://mu.wordpress.org/forums/topic.php?id=10813 i have not that good knowledge with sql…

  4. [...] some web hosts have a restriction on how many subdomains your hosting account allows. Fortunately, subdomains in WPMU can be managed virtually, to circumvent any such [...]

  5. Golf Balls says:

    One prob is that In wp-includes/wpmu-functions.php function install_blog_defaults doesnt work right, what works is creating first blog, about page, blogroll and first comment. It doesn’t create the first post or the links to be added to the blogroll.

    • This is to with fault-intolerant database table definitions – on Windows, inserts will fail if defaults are not set for some columns.

      In WPMU 2.7.1, fix the blogroll inserts by adding link_notes to the insert arrays beginning on line 1430, eg:

      $wpdb->insert( $wpdb->links, array('link_url' => 'URL deleted', 'link_name' => 'WordPress.com', 'link_category' => '1356', 'link_owner' => $user_id, 'link_rss' => 'URL deleted', 'link_notes' => '') );

      (Note: I had to delete the URLs in the array to get this comment past this blog’s spam filter)

      Fix the first post insert by adding the following to the insert array beginning line 1444:

      'to_ping' => '',
      'pinged' => '',
      'post_content_filtered' => '',

      Hope that helps,

      Christian

  6. Monkey Girl says:

    Thx for the help.

    One question…what has to be done to make sub domains work on an IIS6 server (win 2003)?

    I understand that a wildcard(?) needs to be added to our domain’s DNS record. Is it adding a CNAME of ” * ” ?

    We use Plesk control panel and can add this our selves. Is it another name that has to be added?

    Also, I see that there are a few things that have to be done on the server side for apache, but what about IIS6 (Win 2003) ?

    thx.

    m.girl

  7. Monkey Girl says:

    …re above:

    of course I mean in reagrds to making wpmu work using subdomians.

    : )

    I can get mu running and creating add’l blogs…….just can’t surf to them.

    We setup wpmu to use subdomains on the install.

    We also added the * cname to our dns but waht else
    needs to be done.

    thx again.

  8. Art Deco says:

    An htaccess voodoo question:
    I bought an old wp blog where the pages were indexed in G like this

    domainname.com/keywordphrase.php

    and I am setting it up as a wpmu blog using subdomains like this

    keywordphrase.domainname.com.

    I am writing pages with new content but keeping the same keywords, just per blog rather than per page.

    I would like G and any incoming links to see the new page automagically when it crawls the site. So far I just have the default htaccess that WPMU 2.7 creates.

    I’m trying to figure out what I should be putting in there to make the redirects work ? I don’t even know what to search for since searching G for htaccess returns the usual millions of hits.

  9. Monkey Girl says:

    Thx again.

    You stated that: “…also have to add a wildcard record to the httpd.conf file in apache”.

    But that is my problem. I’m using IIS6.

    Now, I have a wildcard * in the CNAME. But I still have to add
    a IIS entry subdomain (eg: newblog.abc123.com) that points to the root of the WPMU folder.

    So every blog I create, I have to create a subdomian IIS entry ?

    That is what I want to get away from….any ideas?

    thanks.
    m.girl

  10. Firewall’s Weekly WordPress, Twitter and Web News « Web hosting says:

    [...] some web hosts have a restriction on how many subdomains your hosting account allows. Fortunately, subdomains in WPMU can be managed virtually, to circumvent any such [...]

  11. menes says:

    hey, my blogs aren’t showing up when I add them.. it just give s me a site not found page..

  12. 2sticks says:

    this is probably too cool. at least I have the experience not to jump to conclusions and start using dns functionality that will get me nowhere. hostmonster does not support the wild card precept. so i dug into my sql after creating a blog in mu and indeed, there it sat all tidy in the tables but of course invisible on the web. I haven’t done yet what you’re suggesting but it looks promising if I don’t have to mess with a support ticket. Am I understanding this correctly??? Thanks for any comment.

  13. sreckop says:

    Hi,
    I installed latest version of WP MU and a default .htaccess file was created.
    I installed version in sub directory.

    When I try to start blog, I see just a blog home directory structure (sub directories and files)
    So to start a blog I need to go to wp-admin/index.php and then it starts.
    However if I try to visit my blog form dashboard again puts me in my default Blog home directory structure.

    Any suggestion?

  14. Kirk Ward says:

    I’m wanting to set up WPMU and would like to point the name used in the DNS to the subdirectory type blog structure (domain.tld/username/)

    Can I do this in a way that will rewrite the domain name (somedomain.com) to the subdirectory (domain.tld/username/) in a way that will avoid having the blog reader seeing the tld path?

    Thanks,
    Kirk

  15. bassel says:

    thanx for that

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-Spam Image