Whilst I recommend you skip to the back story and particularly the assumptions this guide makes before using the code in a production environment, I’m going to start with the end for brevity’s sake.
The End
- In the .htaccess file at the base of your (standard-pretty-permalink enabled) WordPress installation, find the line which contains </IfModule>
- Add a new line above it, and paste these two:
#RewriteCond %{REMOTE_ADDR} ^127\.0\.0\.1$
#RewriteRule ^(index\.php)$ HOLDINGPAGEHERE [L]
- Replace HOLDINGPAGEHERE with the relative path to your maintenance page. It can be any format, try maintenance.html if you’re not sure.
- Remove the # from the beginning of the second (of these two) lines. If you save / upload this file now, all requests to the front of WordPress will be redirected to your maintenance page. Congratulations!
If, like me, you’d like to be able to view and test the site whilst redirecting your visitors, read on:
- Make a note of your public IP address in a note/text-pad window. Use a service like whatismyip.com if you’re not sure.
- For every period / full-stop in your IP address, add a backslash before it.
- On the first line of the two you pasted, delete everything between the ^ and the $
- Paste your slashed IP address from your text window between the ^ and $
- Remove the # from the beginning of the line and save the file. If you’ve done it right, you’ll still be able to see the site and other visitors will get your maintenance page. Try it on your phone, or through a web proxy (I’d link to one but I don’t know any that aren’t ad heavy)
Once you’ve got that setup and working, all you’ll need to do in future is toggle the # characters at the beginning of the line. A hash at the beginning of any line in an .htaccess file ‘disables’ it.
Back Story
This all started with with Jangles (not these Jangles this Jangles) when he tweeted
A little bit of WP housekeeping, like upgrading to 2.8.3. Normal service on the blogs will be back asap :)
Daz then suggested a plugin called Maintenance Mode for WordPress. Jangles said he’d “[…] yet to find anyone who has had a good experience with [it]” and I made the point that it seemed contrary to use a plugin to cover a hole in a system it needed to be running to work. I said I thought a .htaccess redirect was the way to go, but I didn’t have a nice ‘designer-friendly™’ set of steps I could give either of them to get it done.
As I’d brought it up, I thought I’d better make sure there was such a plan if I was going to go around recommending it!
Assumptions
- You’ve got a site up and running WordPress, it needs some updates and you’d rather you didn’t show everyone the guts and garters of your site while you upgrade it.
- One way or another, you can access the .htaccess file.
- That you have the standard ‘pretty’ permalinks enabled. My guess is the guide will work fine for any variant of pretty-permalinks. If you don’t have them turned on, you should! Read more about them here: WordPress Codex: Using Permalinks – mod_rewrite ‘Pretty Permalinks’