One wordpress codebase, many websites

This item was filled under [ Development ]

Today there is a lot of talk about Wordpress 3.0 coming out soon and the merge of Wordpress MU. This will enable you to run several blogs/websites on the same codebase, as I understand it.

If you wish to accomplish this today, you normally install Wordpress MU and some plugin which makes it possible to host several websites or blogs using the same codebase. This is great as is speeds up the process of creating a new website or blog, as well as the maintenance time is reduced. And time is money, so…

I’ve been using Wordpress MU + plugin for almost a year now and it’s working fine. But, some details are annoying, such as the “www” in the URL was lost for me as well as the pinglist. Why not use the regular Wordpress and modify it I thought? All the content is in the database and just dynamically setting the table prefix should do it? Right? Yes? No? The key is to set $table_prefix dynamically using the PHP variable $_SERVER['HTTP_HOST'] .  Well, the solution below works for me so far:

Just update the wp-config.php file (setting the $table_prefix dynamically) similar to as below and point your next domain to join the Wordpress installation and install it.

// get domain requested
$domain = $_SERVER['HTTP_HOST'];
// cleanup $domain so www never is present, and preplace . with _
$domain = str_replace(”www.”, “”, $domain);
$domain = strtolower($domain);
$domain = str_replace(”.”, “_”, $domain);
$table_prefix = “wp_” . $domain . “_”;

Let me know if you have any problems with this solution and Ill try to be more specific.

Advatages using the solution above (Wordpress + modification) instead of WP MU + multisite plugin (IMHO): “www” in the URL (maybe no big deal), pinglist. No 1 advantage: I think it is easier to sell developed domains/websites developed on Wordpress. Extracting a website from WP MU seems difficult.



Popularity: 1,834 views
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Comment