Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have an two wordpress sites that I would like to host on the same domain. One is already up and running, the other is sitting in waiting.

Can I get the second as a subdomain, or simple within a folder, to run on the same domain (different DB) without converting to multisite?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Point the subdomain to the same directory as the main site, and define different settings in your wp-config.php per $_SERVER['HTTP_HOST']:

Example from my local setup:

switch ( $_SERVER['HTTP_HOST'] )
{
    case 'zzl.dev':
        $table_prefix = 'zzl_';
        $table_name   = 'zzl';
        break;

    case 'wpbuch.dev':
        $table_prefix = 'wpbuch_';
        $table_name   = 'wpbuch';
        break;

    default:
        $table_prefix  = 'wp_';
        $table_name   = 'wpdev';
        break;
}

define( 'DB_NAME', $table_name );

You can change much more variables in the switch: all DB_* definitions, WP_PLUGIN_DIR and WP_PLUGIN_URL (to share the plugin list between different sites), WPLANG and so on.

share|improve this answer
    
Is this all I have to do to add a subdomain? –  Mild Fuzz May 11 '11 at 10:27
    
@Mild Fuzz: Yes, I’m running several live sites with this setting, even some multisites. –  toscho May 11 '11 at 10:33
    
so this is just a case of having all themes and plugins in the same install, and just calling the different databases? Ultimately it is one install? –  Mild Fuzz May 11 '11 at 10:35
    
@Mild Fuzz Yes, it is. If you update one site, the other sites are up to date too. Try it in your local setup, it’s a matter of minutes. –  toscho May 11 '11 at 10:50
    
@toscho How does this work out when you come to upgrade plugins and wordpress? Does it play nice? –  Brady May 11 '11 at 12:55
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.