multiBlog – a solution … ish

well, i’ve got a bunch of blogs now all operational off the same codebase.  no, proverbial, worries. save one.

if you select the first permalink structure:

choosing the default permalink structure deletes the rewrite rules

choosing the default permalink structure deletes the rewrite rules

WP removes the redirects from within .htaccess. it’s that straightforward. and without the redirects, the other permalink structures do not work.  but … the solution is to reset one of the other permalink structures on another blog afterwards.  the redirect does not harm the default permalink structure at all.

the other solution is to change the permissions on your .htaccess file to prevent wordpress from overwriting it.

so now, anyway, i have a solution to manage all my wordpress blogs in one place with one code base.  and now i can move wp-content outside of the wp architecture to preserve it during updates (just define WP_CONTENT_DIR in the wp-config.php file), failing this it is defined in wp-settings.php

if ( !defined('WP_CONTENT_DIR') )
	define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); // no trailing slash, full paths only - WP_CONTENT_URL is defined further down

and the solution … it’s gaspingly simple and more or less as I posted previously.  For PDO For WordPress installations you just edit the wp-content/db.php to read

define ('FQDB', FQDBDIR .  strtolower($_SERVER['SERVER_NAME']).'.sqlite');

for classic WP installations i’d just edit the wp-config.php file as follows (this stores all the tables in the same database, with different table names. the preg_replace is needed to conform to wp standards (and maybe SQL) on table names.

// You can have multiple installations in one database if you give each a unique prefix
$prefix = strtolower($_SERVER['SERVER_NAME']);
$prefix = preg_replace('/[^0-9a-z_]/i', '_', $prefix);
$table_prefix  = 'wp_'. $prefix . '-';   // Only numbers, letters, and underscores please!

and …. thinking about it you could also have a hybrid of sqlite and other blogs by doing something like this in your wp-config.php file

...
require_once $_SERVER['SERVER_NAME'] . ".php";

and then create separate mini-configs for each blog. eg. rathercurious.net.php would contain

define ('DB_TYPE', 'sqlite');
define ('FQDB', FQDBDIR .  strtolower($_SERVER['SERVER_NAME']).'.sqlite');

it also occurs to me that this solution works only for domain name based blogs and might fall down nastily if you used wildcard domains (e.g. if www.rathercurious.net directed to the same as rathercurious.net). You can increase the complexity of the rules to take account of this and perhaps it would be worth building a configurator to manage/occlude these edge-cases from the users.

Conversely i don’t think that this solution works so well for directory based blogs. So, say if your ISP only allowed you a single domain name and you wanted to host two blogs: one at www.mydomain.com/blog1 and the other at www.mydomain.com/blog2.

There is an easy solution for this too, completely different to this type of solution though. it’s more native to WP and is described in the WP installation instructions.

Leave a comment

Your comment