Same DB for live and dev versions

It would be bad practice to have two sites running off the same database. This is especially true if you were to perform plugin / core updates on one or the other.

You would be much better off using something like migrate-db (https://wordpress.org/plugins/wp-migrate-db/) to perform a migration.

The maintainers of migrate db are also working on Mergebot (https://deliciousbrains.com/mergebot-beta-update-plugin-integrations-query-selection/) which should safely keep databases in sync although it is still in beta at the moment.

Otherwise, you should take a look at you if statement:

I thing you probably want to query $_SERVER['HTTP_HOST'] rather than$_SERVER['REQUEST_URI']. Request uri will give you the bit of the url after the domain. Http host will give you the domain (and subdomains) that made the request.

You would end up with:

<?php
// paste this in a (new) file, wp-content/db.php
add_filter ( 'pre_option_home', 'test_localhosts' );
add_filter ( 'pre_option_siteurl', 'test_localhosts' );
function test_localhosts( ) {
 if (strcasecmp($_SERVER['HTTP_HOST'], 'rmdemo.bazcreative.com') == 0) {
      return "http://rmdemo.bazcreative.com";
   }
  else return false; // act as normal; will pull main site info from db
}

One thing I would make sure to check that is all to easily forgotten:

  • Make sure you have cleared your browser cache. Browsers like to cache redirects for (imho) far too long. If you visited the “dev” site before implementing this, you would have been redirected to the live site.