0

I'd like to run my test site using the live DB to test a few things before I transfer. I know I can make a copy of the DB, but then I have to keep updating it as the live site progresses.

I followed this Wordpress instruction using the db.php, which I've put in the wp-content folder of both sites, but it doesn't seem to be working.

Can anyone help? site is http://routemaster.lk and WIP site is rmdemo.bazcreative.com

db.php has the following code:

<?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['REQUEST_URI'], 'rmdemo.bazcreative.com') == 0
      || strcasecmp(substr($_SERVER['REQUEST_URI'], 0, 5), 'rmdemo.bazcreative.com') == 0) {
      return "http://rmdemo.bazcreative.com";
   }
  else return false; // act as normal; will pull main site info from db
}
  • Can you be more specific about what isn't working? Are you getting any error messages? Both of those sites are currently loading. – Jared Cobb Apr 23 '17 at 18:28
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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