• The solution here wasn’t quite working for me, so I created the script below. Point all domains you want to the same wordpress directory and replace your wp-config with the following (make sure to edit the variables for each domain):

    <?php
    /* Determining the domain  - DO NOT EDIT */
    
    $host = $HTTP_HOST;
    $parts = explode('.',$host);
    if ($parts[3] = "") {
        $domain = $parts[0];
    } else {
    
        $domain = $parts[1];
    }
    /* Domain - Edit below. Add more "cases" for each domain you want to have.
       Make sure each "case" has a "break; line at the end.                */
    
    switch ($domain) {
      case "domain1":		// "domain" in "www.domain.com"
        $db = "database1";		// the database for this domain
        $user = "username1";	// the username for this database
        $password = "pass1";	// the password for this database
        $hostname = "localhost";	// 99% chance you won't need to change this value
        $table_prefix  = 'wp_';	// change for multiple installations in one database
        $wplang = '';		// change to localize wordpress (must have an MO file in wp-includes/languages)
        break;
    
      case "domain2":		// "domain" in "www.domain.com"
        $db = "database2";		// the database for this domain
        $user = "username2";	// the username for this database
        $password = "pass2";	// the password for this database
        $hostname = "localhost";	// 99% chance you won't need to change this value
        $table_prefix  = 'wp_';	// change for multiple installations in one database
        $wplang = '';		// change to localize wordpress (must have an MO file in wp-includes/languages)
        break;
    }
    
    /* That's all, stop editing! Happy multi-blogging. */
    
    define('DB_NAME', $db);
    define('DB_USER', $user);
    define('DB_PASSWORD', $password);
    define('DB_HOST', $hostname);
    
    define('DB_CHARSET', 'utf8');
    define('DB_COLLATE', '');
    define ('WPLANG', $wplang);
    
    define('ABSPATH', dirname(__FILE__).'/');
    require_once(ABSPATH.'wp-settings.php');
    
    ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi,

    Great post! it works!

    i was just wondering if you have a solution for subdomains ex(1.domain.com & 2.domain.com)… it does not seems to work in subdomains.

    I’ve been reading for a week now and your solution above seems so much easier than everything else I’ve come across. One question though – when you say “Point all domains you want to the same wordpress directory” are you talking about redirecting or symbolic links – or does it not matter?

    Hey Cusnum,
    If you read this, can you respond to kathleane’s question, please.
    Fn STDestiny doesn’t seem to be reading this board anymore.
    I have been spending way too much time on this issue, and I have none, and some stupid little question is not answered.
    RDB

    The solution given by STDestiny is the simplest I have come across too. However, I host on IIS6 and the $HTTP_HOST was returning null and thus I got HTTP 500 error when I used the script as is.

    I had to change that line, just like the original solution you referred, to make the config work :

    $host = $_SERVER['HTTP_HOST'];

    Place the following in a test.php and call it using https://www.yourdomain.com/test.php to check which will work for you:

    <?php
        echo '<pre>';
        var_dump($HTTP_HOST);
        var_dump($_SERVER['HTTP_HOST']);
        echo '</pre>';
    ?>

    One improvement can be made to the SWITCH statement in this wp-config.php file – add a default value to handle any erroneous situation. Add the following after the last ‘break;’ statement and put before the closing curly brackets:

    default:		// default config if everything fails
        $db = "defaultdb";	// the database for this domain
        $user = "defaultuser";	// the username for this database
        $password = "defaultpw";// the password for this database
        $hostname = "localhost";	// 99% chance you won't need to change this value
        $table_prefix  = 'wp_';	// change for multiple installations in one database
        $wplang = '';		// change to localize wordpress (must have an MO file in wp-includes/languages)

    Good thinking…STDestiny!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Multiple domains using one WP install (not wpmu)’ is closed to new replies.