WordPress.org

Ready to get started?Download WordPress

Forums

Multiple domains using one WP install (not wpmu) (5 posts)

  1. 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');
    
    ?>
  2. cusnun
    Member
    Posted 6 years ago #

    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.

  3. kathleane
    Member
    Posted 6 years ago #

    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?

  4. rdbranson
    Member
    Posted 6 years ago #

    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

  5. sgsaid
    Member
    Posted 6 years ago #

    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 http://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!

Topic Closed

This topic has been closed to new replies.

About this Topic