Wordpress multiple server link problem

Wordpress siteurl and home configuration

Two images of a house, one is normal and the other has been manipulated to look like it is hauntedWordpress isn't really designed to work on multiple servers and there are two configuration values that cause major problems in this regard. The siteurl and home configuration values can be found in the wp_options table.

If you check this table for the two values you will find two URL's. These will be hard coded values based on the location of the server where you installed wordpress. Once you transfer the database to another server the two configuration values will cause problems. What we need to do is override them so each server has it's own locations.

Open up the wp-config.php file and add the following code:

define('WP_SITEURL', 'http://www.marcwatts.com.au'); define('WP_HOME', 'http://www.marcwatts.com.au');

We could also have our values more flexible by using our HTTP_HOST apache variable.

define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']); define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);

Not all my websites are located in the DOCUMENT_ROOT apache directory so a more sophisticated configuration file maybe needed. Below is an example of recommended wp-config.php configuration statements to fix our multiple server wordpress problem.

if (strpos($_SERVER['HTTP_HOST'], 'localhost') !== false) { //local define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/websites/marcwatts.com.au'); define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/websites/marcwatts.com.au'); } else if ($_SERVER['HTTP_HOST'] == '10.1.1.4') { //dev define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/websites/marcwatts.com.au'); define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/websites/marcwatts.com.au'); } else if (strpos($_SERVER['HTTP_HOST'], 'staging.') !== false) { //staging define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/marcwatts.com.au'); define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/marcwatts.com.au'); } else { //live define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']); define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']); }