Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
WordPress 3 Ultimate Security

You're reading from   WordPress 3 Ultimate Security WordPress is for everyone and so is this brilliant book on making your site impenetrable to hackers. This jargon-lite guide covers everything from stopping content scrapers to understanding disaster recovery.

Arrow left icon
Product type Paperback
Published in Jun 2011
Publisher Packt
ISBN-13 9781849512107
Length 408 pages
Edition 1st Edition
Languages
Concepts
Arrow right icon
Toc

Table of Contents (23) Chapters Close

WordPress 3 Ultimate Security
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface
So What's the Risk? Hack or Be Hacked FREE CHAPTER Securing the Local Box Surf Safe Login Lock-Down 10 Must-Do WordPress Tasks Galvanizing WordPress Containing Content Serving Up Security Solidifying Unmanaged Defense in Depth Plugins for Paranoia Don't Panic! Disaster Recovery Security Policy Essential Reference Index

Securing your users


This should be your overriding concern.

A server or site with issues can lead to more than functional problems, downtime, and data loss. It can lead to a lack of user confidence, the spreading of malware, the sliding of your hard-won search engine ranking, and ultimately, of wasted time and income.

Considering maintenance mode

If you've clearly been hacked or are trying to wrap your head around an uncertain issue, to play it safe, bring the site safely down into maintenance mode.

There are two ways to do this.

Using a plugin

If you have a functioning Dashboard, you could use a plugin such as Michael Wöhrer's aptly named Maintenance Mode to inform visitors that your site's taking some time out:

On the plugin's options page, ensure that you set the Splash Page Theme preference to Use 503.php from theme folder and check the box Apply HTTP header '503 Service Unavailable' and 'Retry-After <backtime>' to Maintenance Mode splash page. Properly, that throws a 503 Error (service unavailable) to stop search spiders from trawling the site, giving you the chance to mop up any salacious spam that would otherwise get indexed (possible porn links and all!). Logged in admins, meanwhile, retain full access:

Using a rewrite rule

Then again, you may prefer or have no alternative but to create a splash screen, similar to using the previous plugin, and again with that all-important 503. As with the plugin, this will reroute everyone but you. There are two steps:

  • Create a maintenance.php page to inform search bots and regular visitors

  • Create an htaccess rule to rewrite regular traffic to the maintenance page

Here's the code for the maintenance.php file, which must live in your WordPress root folder. Change SomeSite for your site and otherwise customize to suit:

<?php
  header('HTTP/1.1 503 Service Temporarily Unavailable');
  header('Status: 503 Service Temporarily Unavailable');
  header('Retry-After: 7200');
  header('X-Powered-By:');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>503 - Temporarily Undergoing Maintenance</title>
</head>
<body>
  <h1>SomeSite.com is Temporarily Undergoing Maintenance</h1>
  <p>Thanks for popping by. Unfortunately you've caught SomeSite justas it's having a tweak. We won't be long, all that.</p>
</body>
</html>

Of the directives in the <head> to </head> section, the variable you may want to change is header('Retry-After: 7200');, where 7200 is the number of seconds you are telling search bots to wait before coming back.

Now we can force everyone but you to go to the maintenance page by adding a directive in the htaccess file, again in your WordPress root directory:

RewriteEngine On
RewriteBase /
# Provide an exception for your IP. Swap 123.45.67.890 for your IPbut leave the backslashes before the three periods.
RewriteCond %{REMOTE_ADDR} !^12\.345\.678\.90$
# If any page is accessed, other than maintenance.php which doesn't need the exception ...
RewriteCond %{REQUEST_URI} !^/maintenance\.php$
# ... then rewrite the request to the maintenance page.
RewriteRule ^(.*)$ /maintenance.php [L]

Note

Got a local dynamic IP? Sod's law says that, having set this up, you'll drop your web connection, log back on with a new IP and, because the new rule wants your old IP, lose access! No worries. SSH or SFTP into the htaccess file to switch the old IP reference for the new one. Then you can regain access. Sweet.

That was a good insurance policy that you can remove once the site is back on track.

Now let's isolate the trouble.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image