Use WordPress to Setup Multi Blogs Under One Mysql Database

We can use Mu to setup multi wordpress blogs. If you do not want to do so, you can use wordpress to setup multiy blogs also.

 For example, we want to set up two blogs: www.glassespeople.com ,and http://blog.glassespeople.com, we only add the following code at wp-config.php:

if($_SERVER[“HTTP_HOST”]==”www.glassespeople.com” || $_SERVER[“HTTP_HOST”]==”glassespeople.com”){

define(‘DB_NAME’, ‘www’);
define(‘DB_USER’, ‘www_usr’);
define(‘DB_PASSWORD’, ‘www_psw’);
define(‘DB_HOST’, ‘localhost’);
define(‘DB_CHARSET’, ‘utf8’);
define(‘DB_COLLATE’, ”);

}else if($_SERVER[“HTTP_HOST”]==”blog.glassespeople.com” || $_SERVER[“HTTP_HOST”]==”blog.glassespeople.com”){

define(‘DB_NAME’, ‘blog’);
define(‘DB_USER’, ‘blog_usr’);
define(‘DB_PASSWORD’, ‘blog_psw’);
define(‘DB_HOST’, ‘localhost’);
define(‘DB_CHARSET’, ‘utf8’);
define(‘DB_COLLATE’, ”);

}

 One more example:

$hostname = $_SERVER[‘SERVER_NAME’];
$hostname = str_replace(‘www.’, ”, $hostname);

// switch($_SERVER[‘HTTP_HOST’])
switch($hostname)
{
case “ozoptical.com”:
$table_prefix  = ‘wp_’;
break;

case “eyeglassesshop.com.au”:
$table_prefix  = ‘eyeglassesshop_’;
break;

case “discountglasses.net.au”:
$table_prefix  = ‘discountglasses_’;
break;

case “eyeglassesonline.net.au”:
$table_prefix  = ‘eyeglassesonline_’;
break;

case “discounteyeglasses.net.au”:
$table_prefix  = ‘discounteyeglasses_’;
break;

case “cheapeyeglasses.net.au”:
$table_prefix  = ‘cheapeyeglasses_’;
break;

case “buyglasses.net.au”:
$table_prefix  = ‘buyglasses_’;
break;

case “glassespoint.net”:
$table_prefix  = ‘glassespoint_’;
break;

case “zennioptical.com.au”:
$table_prefix  = ‘zennioptical_’;
break;

case “selectspecs.com.au”:
$table_prefix  = ‘selectspecs_’;
break;

case “glassescrafter.com.au”:
$table_prefix  = ‘glassescrafter_’;
break;

case “eyebuydirect.com.au”:
$table_prefix  = ‘eyebuydirect_’;
break;

case “ozoptical.com.au”:
$table_prefix  = ‘ozopticalau_’;
break;

case “ozoptical.net”:
$table_prefix  = ‘ozopticalnet_’;
break;

case “ozeyeglasses.com”:
$table_prefix  = ‘ozeyeglasses_’;
break;

case “ozspectacles.com”:
$table_prefix  = ‘ozspectacles_’;
break;

case “ozspectacle.com”:
$table_prefix  = ‘ozspectacle_’;
break;

default:
$table_prefix  = ‘buyeyeglasses_’;
break;
 }