26 November 2011

WordPress Multisite Domain Mapping - ISPConfig 3

I'm going to assume you're familiar with setting up and installing WordPress and installing plugins and have an intermediate knowledge of hosting and domains.
This isn't a tutorial, more of a checklist, but if you have any questions then please ask in the comments below.

If you're setting up a WordPress multisite network on your server with ISPConfig 3 control panel, the workflow is mostly the same as the tutorials you can find by searching with your favourite search engine. There are, however, two important things to get right (highlighted red) that if not correct will result in endless redirect loops.  The 'Aliasdomain' section isn't covered in any tutorials I could find, but this slots in where the official tutorial talks about 'parking' names in cPanel (a more popular control panel solution).

Example Site: example.com, blog2.example.com, example.org
Example IP: 217.145.318.277
(Replace with your own details- IP address is impossible anyway!)

Set up domain in ISPConfig:
Set up DNS details making sure you have A records for 'www', '*' and ' ' (i.e. blank) all pointing to the server's primary IP address
-- So www.example.com, example.com and everythingelse.example.com at the moment all point to your index.html page on example.com
Set up a site for your primary domain (where you'll install WordPress).

Installing WordPress & Plugins:
Install WordPress (I'm using 3.2.1). Set up your primary blog on example.com
Follow instructions for setting up a multisite network.
Install and activate the plugin Wordpress MU Domain Mapping.
Install and activate the plugin Better HTTP redirects.

Mapping Domains:
Create your secondary blog e.g. 'Blog2' which is now at the address blog2.example.com.
From the Settings menu, choose 'Domain Mapping'.  If you were hosting your WordPress install on your server's default domain, you could put the IP in and omit CNAME, but as we're installing on a server that we're sharing with many domains, ignore IP and in CNAME enter the main blog domain i.e. example.com
In 'Domain Options' on the mapping page, select options 1, 2, and 4.
Next choose the option 'Domains' from the Settings menu.  In 'Site ID' enter '2' (assuming this is a fresh install and the first sub-blog you've set up, else find your ID from the 'Sites' menu) and in domain enter example.org. IT IS VERY IMPORTANT THAT DOMAIN IS ALL IN LOWERCASE! Tick/check the 'Primary Domain' option and click save.

Setting Up Secondary Domain:
At your registrar, find where you can edit your DNS settings.
Remove any A records for ' ' (i.e. blank) - sometimes represented as '@', '*' and 'www'.
In their place create CNAME records for each of the above, pointing at 'example.com'.

Alternatively, if your name servers already point at your ISPConfig server, you can create the domain name under 'DNS' and change the settings on the ISPConfig server as outlined above.

Alias To Main Site
In your ISPConfig control panel, select the 'Sites' menu option, and then the 'Aliasdomain for website' from the left-hand menu.
Choose to 'Add new alias domain'.
In 'Domain' enter example.org
For 'Parent Website' select example.com from the drop-down menu.
For 'Redirect Type' select 'No Flag' from the drop-down menu.
Leave 'Redirect Path' blank, and for 'Auto Subdomain' select '*.' from the drop-down menu and make sure 'Active' is ticked/checked.

Sometimes, DNS settings take a while to work, so I would suggest taking this opportunity to make some tea/coffee.

Now, visiting example.com should take you to your primary blog, example.org should take you to Blog2 and if anyone entered blog2.example.com, they should get redirected to example.org (which should display in the address bar).  All sites can be managed from the 'Network Admin' page which you can reach from the WordPress dashboard (at 3.2.1 this is where it says 'Howdy, Yourname", but this will be slightly different in 3.3).

Update [Feb 2014]: +Gwyneth Llewelyn has posted a helpful comment containing a method for nginx users to utilise the benefits of W3 Total Cache: https://plus.google.com/117667414309209066991/posts/SsWV8EXds5c
She also points out that the 'Better HTTP redirects' plugin is no longer maintained (I've just realised this post is over two years old!) and may not be required. I deactivated on one of the few WP Multisite installs I have remaining and there seems to be no adverse effects. (YMMV).