In my config.php, I use case to set Perch settings for dev, staging and live sites. An easy way to prevent dev and staging sites from being indexed by search engines is to define an extra setting:

switch($_SERVER['SERVER_NAME']) {

    case 'blah.localdev':
        define("PERCH_DB_USERNAME", 'blah');
        define("PERCH_DB_PASSWORD", 'blah');
        define("PERCH_DB_SERVER", "localhost");
        define("PERCH_DB_DATABASE", "dev_blah");

        define("SITE_NOINDEX", true); // NOINDEX SETTING
        break;

    case 'blah.staging.com':
        define('PERCH_DB_USERNAME', 'stage_blah');
        define('PERCH_DB_PASSWORD', 'blahblahblah');
        define('PERCH_DB_SERVER',   "localhost");
        define('PERCH_DB_DATABASE', 'stage_blah');

        define('SITE_NOINDEX', true); // NOINDEX SETTING
        break;

    default:
        define('PERCH_DB_USERNAME', 'live_blah');
        define('PERCH_DB_PASSWORD', 'blahblahblah');
        define('PERCH_DB_SERVER',   "localhost");
        define('PERCH_DB_DATABASE', 'live_blah');
        define('PERCH_SSL', true);
        break;
}

 

Then, in the <head> of your header, add this line:

<?php if (defined('SITE_NOINDEX')) { echo '<meta name="robots" content="noindex, nofollow">'; } ?>

 

Categories: