WPMU Installation to support sub-domain blogs

wordpressI’m currently renovating a site of mine – Coffeehouse Chat – with a possible view to re-opening the Forum side of it with new and improved features – including better integration with Social Media and User Blog hosting on the site.  And there was the issue – I wanted to install WordPress-MU – the multi-user edition of WordPress – in such a ways so as to support user blogs in sub-domains on the main site domain – e.g. something like joesblog.blogs.coffeehousechat.co.uk

This is a two stage process that is outlined in the documentation.  the first part is the setting of Wildcards in the DNS settings for the server, and the second part is installing a .htaccess file that actually handles the processing of the redirected incoming requests.

Installing the .htaccess file is nice and easy.  the file is below – it comes with WordPress-MU named as htaccess.dist – simply put it in the directory containing the WordPress sofwtare and rename it to .htaccess.

RewriteEngine On
RewriteBase BASE/

#uploaded files
RewriteRule ^(.*/)?files/$ index.php [L]
RewriteCond %{REQUEST_URI} !.*wp-content/plugins.*
RewriteRule ^(.*/)?files/(.*) wp-content/blogs.php?file=$2 [L]

# add a trailing slash to /wp-admin
RewriteCond %{REQUEST_URI} ^.*/wp-admin$
RewriteRule ^(.+)$ $1/ [R=301,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]

<IfModule mod_security.c>
<Files async-upload.php>
SecFilterEngine Off
SecFilterScanPOST Off
</Files>
</IfModule>

So in my case – WordPress-MU installed in a folder called blogs – this file goes in to that folder.

Now, the second part – the Wildcard DNS settings.  Some time ago when I set up an installation of WordPress-MU I had to get my hosting comapny to deal with this for me.  However, this time, a little advice from Samuel at Prime Hosting showed me how to set it up from within cPanel, so I’m going to share that with you here.  If you’re not using cPanel, there may be other ways in your own control panel to do this.

In my installation, WordPress-MU is installed in a fodler called blogs off the root of my public_html directory.  I have set up a subdomain – blogs.coffeehousechat.co.uk – to point to it, so that when a user enters this domain they go to the blog create / sign in page.  Now, after checking that this worked happily, I logged in to cPanel for the coffeehousechat.co.uk domain and selected the ‘Subdomains’ control from the Domains panel.

Now the cunning bit…note that this may not work for you in complicated web site set-ups where multiple redirects are involved – but it worked for me.

In the ‘Create a Subdomain’ box, (below) enter ‘*’ as the subdomain name – giving *.coffeehousechat.co.uk in my case – and enter the folder on the server where you want things to redirect to as the ‘Document Root’ – in my case public_html/blogs.

 

 CreateSubDomain

 

 

 

 

 

 

Once this is entered, press the create button.  The grid at the foot of the screen should be updated to reflect teh changes just made:

ListSubdomains

 

 

 

 

 

And that is that! 

A user entering, say, www.test.blogs.coffeehousechat.co.uk will be directed to that blog if it exists, or be prompted to create it.