Managing beta sites in wordpress

Managing a development and live site

As is often the case when developing a new site for a client you have to work with a beta site to show-case the work to its stakeholders  and in parallel deploy updates to a live site.  In such a scenario one ideally wants the live site to be searched and indexed by search engines, and the beta site to remain hidden from public view.

So how does one reconcile these requirements is a question I have have been scrutinising and I share here the information so far gathered so that others may solve this problem too.

Stopping search engines from indexing the beta site

WordPress enables a single check-box setting from being enabled to dissuade search engines from indexing the pages of the a site.  You will find the setting in the admin Dashboard menu Settings->Reading.  However, you should be aware that it is up to the search engines to comply with the request.
Search engines indexing setting in WordPress Dashboard

One should also be aware that this works only for sites that are installed in the root folder of your site and not for sites that live in a separate folder.  In this case several other options are available, such as placing a robots.txt in your installation folder.

Locking down the beta site

The basic idea here is to enable views of the beta site to users with an account on the beta site.   I make use of the template_redirect hook in the functions.php file to redirect any request from the front page to a nice looking static html landing page…

function beta_site_redirect() {
    if (!is_user_logged_in() && !is_admin()) {
        //&& !'redirect.html'==get_current_template()
        //echo get_current_template();

The function checks if the request comes form a logged in user as well as where the request is coming from.  This ensures that we can still access the admin Dashboard and sign in as usual.  Once signed in we can then proceed to look at the front pages.

In order to make the experience a little more seamless, we redirect the visitor to a static html which informs them that they currently on the beta site and are being automatically redirected to the live site using the following html header:

<title> The CSR Journal</title>
<meta http-equiv="refresh" content="2;url=">

The first number in the content attribute, content="2;..." is the time in seconds before the page is redirected to the url address given after the semi-colon.

IMPORTANT NOTE: make sure your static html is in the root directory of your WordPress installation and not in your theme folder!

Redirect your beta site SEO

if you find yourself in the situation where your beta site has a better page rank than your live site, then you can redirect them to your live site once you have finished the development cycle….