*** UPDATE ***
This hack is probably unnessesary, I found that wp-mu has a sites framework that is not exposed, there is a plugin that’s trying to accoplish the same thing I am. Just google ‘wordpress mu sites’
*******
I need to have multiple wordpress instances installed, but I want them each to have their own vhost, I also want an easy way to maintain them (upgrades and such). I thought wordpress mu could do this… but out of the box it only supports wildecards on a single domain. (blog1.example.com and blog2.example.com and blog3.example.com) Turns out you can change 2 lines (3 if you want to clean up a view cosmetically) and you seemingly can use wordpress-mu to host multiple domains. www.blog1.com and www.blog2.com and www.blog3.com
I’ve not deployed this yet… so use at your own risk. I’ll post again later with results after I’ve migrated a couple sites to it.
The problem: wp-mu assumes in vhost mode that all your blogs are of convention {something_here}.example.com. It does this by concatenating the domain you configure at install time onto the name of any new wordpress site you setup.
The solution: tell it not to append your installed time configured domain when you setup a new site. No special magic seems to happen with a new wordpress site’s configured domain after install time.
To show how this works this we’ll setup an example.com instance of wordpress mu and replace the wildcard magic so that not-example.com is hosted by the same code base.
1. download and and install wp-mu just as they tell you to, use example.com (set a hosts record to point example.com to your localhost) You’ll now have a fresh new wp-mu blog at example.com.
2. patch the files to remove the wildcard vhost magic
a. This change will remove the hardcoded base domain and will assume the domain name you’re accessing wordpress with is the current domain. Without amking this dynamic the authentication would fail on some or all of the configured sites.
wp-config.php
@@ -38,7 +38,7 @@
-define(‘DOMAIN_CURRENT_SITE’, ‘example.com’);
+define(‘DOMAIN_CURRENT_SITE’, getenv(‘HTTP_HOST’));
b. This is the concatenation magic that we want to prevent from happening. It undoes the “force append install-time configured domain” or in our example case, don’t force .example.com on the back of my new blog.
wp-admin/wpmu-edit.php
@@ -147,7 +147,7 @@
if( constant(‘VHOST’) == ‘yes’ ) {
- $newdomain = $domain.”.”.$current_site->domain;
+ $newdomain = $domain;
c. This last one is optional. It’s just removes the domain name below the test box on the form for a new blog. This is a pure cosmetic change.
wp-admin/wpmu-blogs.php
@@ -582,7 +582,7 @@
<?php if ( constant( “VHOST” ) == ‘yes’ ) { ?>
- <input name=”blog[domain]” type=”text” title=”<?php _e(‘Domain’) ?>”/>.<?php echo $current_site->domain;?>
+ <input name=”blog[domain]” type=”text” title=”<?php _e(‘Domain’) ?>”/>
3. Add a new wp site at not-example.com (add the hosts record that points to localhost again to test)
4. use the dashboard -> tools -> export to get an xml dump of a single instance blog that you can import into a wp-mu managed blog.
Like I said I’ve not actually deployed this yet, but authentication in and out of the two domains dashboard and frontend seem happy. I’ll be sure to update this post with any other issues I come across. let me know if you try it and if it works!