Jeremy Simkins | Web Developer


Multiple Domains Off a Single Install of WordPress

Filed Under: WordPress

I was in the need to have multiple domains run from a single install of WordPress but wanted them to have their own database.

WordPress has a nice multi-site system but I am not working on subdomains and I don’t care for a network.
I did some searches on google and never found anything really useful so I created a quick script to handle the multiple domains on a single install.

To install the script:
Edit your wp-config.php, add this code to the top of the file:

 * WordPress Multiple Domains
 * Loads configs based on domain
 * If no config is found initial WordPress install is used
 * Config files are stored in '_domains' in the WordPress directory
 * Config naming convention: {$domain}_wp-config.php
 *  $domain does not use www.
 * @package WordPress
 * @author Jeremy Simkins
/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
    define('ABSPATH', dirname(__FILE__) . '/');

$website = strtolower(str_replace('www.', '', $_SERVER["SERVER_NAME"]));
$website = preg_replace('[^a-z0-9\.-]', '', $website);

// Check if there is a domain config
if (file_exists(ABSPATH . '/_domains/'.$website.'_wp-config.php')) {
    require_once(ABSPATH . '/_domains/'.$website.'_wp-config.php');
    return; // Step out of file
} // If no config is found, defaults to initial install (could throw an error if forced to use this method)
// End - WordPress Multiple Domains

In your WordPress directory (same as wp-config.php), create a directory named: _domains. Store all domain configs in this directory to have multiple domains run from a single install of WordPress. When saving the configs to the domains folder, make sure to name them using the naming convention in the above snippet.

It’s a pretty simple script, hope you find this useful.

I did want to make note on one issue that I haven’t worked out yet. This would be the uploads directory. I am not sure if this is even an issue yet but it seems possible… There may be a chance of upload collisions between the sites. For development this is not an issue (at least for me) but on a site in production this could be catastrophic.

I did find out that the media manager does not conflict. There seems to be no issues with running multiple installs using this method.

3 Responses to “Multiple Domains Off a Single Install of WordPress”

  1. Kenny GAugust 31st, 2013 at 8:28 pm

    How will this work with wp-load.php that hardcodes the name
    wp-config.php ?

  2. SoN9neSeptember 2nd, 2013 at 1:18 am

    Because this modifies the wp-config file to load the proper config for the requested URL. Notice the only real edits are to the config file. The config changes are what loads the sites’ config.

  3. Kenny GSeptember 2nd, 2013 at 8:38 pm

    Sorry, I don’t know where I got that this was creating a new config file.

    Since WP does store uploads in the wp-content/uploads folder, it might be necessary to add something like the following to the section:

    # Store uploads of in /var/www/wp-uploads/$0
    RewriteEngine On
    RewriteRule ^/wp-uploads/(.*)$ /var/www/wp-uploads/%{HTTP_HOST}/$1

    Some that are hacking multi sites to work with individual domains are using the above to handle the uploads directory.

Leave a Reply


Jeremy Simkins is an accomplished senior web developer with over ten years in the production field. Experienced PHP developer as well as a passionate software engineer. Jeremy specializes in code optimization, performance, and implementation.

View Jeremy Simkins's profile on LinkedIn

Open Source Projects




Copyright ©2009 Jeremy Simkins

Warning: fsockopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home2/nghostco/public_html/jeremysimkins/wp-content/plugins/wp-shortstat/wp-shortstat.php on line 128

Warning: fsockopen(): unable to connect to udp:// (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /home2/nghostco/public_html/jeremysimkins/wp-content/plugins/wp-shortstat/wp-shortstat.php on line 128

Warning: stream_set_timeout() expects parameter 1 to be resource, boolean given in /home2/nghostco/public_html/jeremysimkins/wp-content/plugins/wp-shortstat/wp-shortstat.php on line 129