Multiple Blogs, Domains with wordpress

The configuration features now available in wp-config.php now offer you a great deal of flexibility if you have multiple domains parked at the same host or multiple blogs where you wish to share one or more of the database or  the code.

Move the wp-code

First of I’d suggest keeping the wp-code out of the main directory.   Read Giving_WordPress_Its_Own_Directory

This will give you the flexibility of serving other code more easily.  Eg: one parked domain may be redirected to a subdomain not using wordpress at all.

Defining the siteurl overrides the option table.  Plugin developers should use this and not fetch it from the options table.

define('WP_SITEURL', '');
define('WP_HOME', '');

Index.php example:

if (strstr($_SERVER['SERVER_NAME'], "")) {
    // serve up the default wordpress index.php code
    define('WP_USE_THEMES', true);
elseif (strstr($_SERVER['SERVER_NAME'], "
    // redirect to the subdomain, passing the query string along
    header( 'Location:'.$_SERVER['REQUEST_URI']) ;

If statement

In the wp-config.php file, code an if statement similar to above  to determine what your url request is (eg: which domain name) and set the appropriate field to achieve the effect noted below.

Plug-in authors beware – plugins must be tested with these various schemes

Plugins must use these constants or run the risk of not working on some installations.  Users should check all aspects of their plugins.

Configuration values

Multiple Installations in One Database

// You can have multiple installations in one database if you give each a unique prefix
$table_prefix  = 'r235_';   // Only numbers, letters, and underscores please!
define('DB_NAME', 'MyDatabaseName'); // Example MySQL database name

Share Code, but not Themes or Plugins

Move the wp-content directory and define the following:

define( 'WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/blog/wp-content' ); and
define( 'WP_CONTENT_URL', 'http://example/blog/wp-content');

Warning if Moving

Don’t forget to change the settings in the Miscellaneous settings for your uploads

Advanced Options

There are more advanced options too, using for example:

  define('TEMPLATEPATH', get_template_directory());
  define('STYLESHEETPATH', get_stylesheet_directory());

Note: beware:
Multiple domains sharing the same wordpress installation must have the same permalink structure - changes to one will edit the .htaccess, which will then override the previously set permalink.