Skip to content

NO ENTRY! (While You Work)

2011 August 16
by James Kenton

Studio based photograph of James KentonWhen you first begin work on your Affiliate site you’ll probably want to stop people and Search Engines being able to see it until it’s looking good and has quality SEO articles.

In truth very few people are going to accidentally stumble upon your site but you might get some search engine traffic — and you may not want to be indexed on your not-ready-yet content.

Here are two ways to stop prying eyes:

But First…

As soon as you’ve finished installing WordPress go to Settings, Privacy and choose ‘I would like to block search engines, but allow normal visitors’. This stops WordPress reporting the changes you make to Ping services; making it less likely that a search engine will stop by. Don’t worry — you can (and should) change this setting back when you’re ready to go public.

Isn’t robots.txt Good Enough?

Using a robots.txt file is one way to prevent being indexed by the reputable Search Engines. I always put the standard disallow request on my new sites. I prefer to go a little further for the following reasons::

  • First, robots.txt only applies to search engines. It won’t stop people looking at your site;
  • Second, robots.txt is seen only as a polite request by search engines — it doesn’t prevent a search engine from indexing your site. We know that the major search engines will obey the robots.txt as far as their public results are concerned but I know for certain that other bots check out my sites, robots.txt or not. I’d rather stop them seeing anything until I’m ready.

Method #1: Using a Plug-in

One of the fantastic things about WordPress is that there’s a plugin for just about anything you want it to do. Search for ‘Maintenance Mode’ in the plug-ins page and you’re sure to find something suitable.

Screenshot of ThemeFuse Maintenance ModeMost of these plugins will only allow Admin users to see the blog; everyone else sees a nice page (often with a countdown timer).

Last time I checked this one produced a very professional looking customizable page and worked well; but there will be others. Simply find one you like and activate it.

I’d recommend Method #1 for most people.

Method #2: Doing It Yourself

Some people don’t trust plug-ins and/or would rather do the tech things themselves. If you use a webhost that uses Apache servers (which most do) here’s how to stop anyone who doesn’t share your ‘IP Address’ from seeing your blog.

In case you’re not sure: your IP address is the address that the computer you are working from uses to tell other computers on the Internet (including your WordPress host) where to send the pages, images and files that you ask for. It’s a bit like a telephone number … but for computers.

Almost everyone in the world will use a different IP address to you. If you share an Internet connection with other people (within the same house, workplace or school perhaps) they’ll probably share your IP address. So this method won’t keep absolutely everybody out — but it’s good enough for most practical purposes.

Using .htaccess

.htaccess is a special file used by the majority of websites. It can contain special instructions that your website will obey.

After you’ve installed WordPress there will be an .htaccess sitting in the same directory that holds your WordPress files. You may have more than one .htaccess file so ensure you’ve found the right one.

Use your favorite FTP program or CPanel tool to find it.

Unless you’ve installed a plugin that modify this file it will probably contain the following text:

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

If it doesn’t you may be using a version of WordPress that’s different to the one I wrote this post for — so be careful.

Step 1

Make a backup copy of your .htaccess file in case you mess it up. Keep it somewhere safe as you may need to copy it back if things go wrong.

If you are not confident about how to perform this step I’d advise you not to continue. Messing up your .htaccess file(s) can instantly stop your blog working, cause a lot of work to fix and affect your site’s security. Don’t proceed unless you’re confident with this kind of thing: the plug-in method might be better for you.

Step 2

Create a file called maintenance.html and save it in your webspace. This file should be a valid html file and contain whatever you want to be displayed while you’re working. Put it in the same directory as your .htaccess file.

Step 3

Make a note of your public IP address. If my calculations are correct your public IP address is currently 38.107.179.227

If you’d like to double check try this service.

Note that your public IP address is likely to change regularly so you may need to come back here and check it regularly (see below).

Step 4

To put your site in to ‘Maintenance Mode’ copy this code to the top of your .htaccess file and then save it. Make sure you don’t delete anything else that might have been there.

# BEGIN Maintenance Redirect from all but a specific IP address ###
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.html$
RewriteCond %{REMOTE_ADDR} !^38.107.179.227
RewriteRule $ /maintenance.html [R=302,L]
</IfModule>
# END Maintenance Redirect

(Making sure that the number that I’ve highlighted in yellow is your public IP address.)

Checking It Works

If you go to your domain now nothing should have changed! You’ll see your WordPress site as normal. This is because you are viewing it from the allowed IP address. If someone from a different IP address tries they’ll see your maintenance page.

To check everything’s working: change the IP address in your .htaccess file to something that isn’t yours — I normally just add 1 to the final number.

When you’re happy it’s working, change the IP address back to your own. Now you can begin work on your site knowing that the search engines aren’t going to be able to see it — until you allow them.

You Can Bookmark This

You may have an IP address that stays the same forever but that’s rare. For many people it changes every time they cycle their router or connect to the Internet using dial-up.

During your setting up period whenever your IP address changes you’ll need to change it in the .htaccess file — otherwise you’ll be taken to the maintenance page too. Just repeat the steps. If you don’t you’ll see the Maintenance Page instead of your WordPress.

Every time you come back to this page it should show your current IP address — so you can overwrite the old code in to your .htaccess file.

To jump straight to the code (rather than scrolling down to find it) bookmark this page.

Problems?

WordPress and Apache change regularly — so maybe this method isn’t working right now. Just delete the text that you added (and only the text you added), save the file and all will work again normally.

Finally

When you’re ready to let people in to your store remember to go to Settings | Privacy and allow the Search Engines — you need them!

Then either disable your Maintenance Page plugin or remove the lines you added to your .htaccess file.

As ever, I wish you every success.

James' hand written signature

James