Quick maintenance mode with .htaccess
How to make a quick WordPress maintenance mode with .htaccess
30.03.23
It’s always nice to avoid using plugins if you can and we find this method of maintenance mode to be clean and fast. It’s especially good because we can blog the admin from the client but not us. We may not want the client in the backend making changes during a server migration for example.
Simply create a simple HTML maintenance page with no images. You can do this via the terminal.
$ nano maintenance.html
Then paste in the generic Site Maintenance page as HTML below.
<!DOCTYPE html>
<title>Site Maintenance</title>
<style>
body { text-align: center; padding: 150px; }
h1 { font-size: 50px; }
body { font: 20px Helvetica, sans-serif; color: #333; }
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
a { color: #dc8100; text-decoration: none; }
a:hover { color: #333; text-decoration: none; }
</style>
<article>
<h1>We'll be back soon!</h1>
<div>
<p>Sorry for the inconvenience but we're performing some maintenance at the moment. We'll be back online shortly!</p>
<p>- The Team</p>
</div>
</article>
Exit nano and save this file.
Then you need to update the .htaccess with a redirect to your maintenance.html page. This will block all traffic to your site and admin areas.
$ nano .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^192\.3\.2\.1
RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
RewriteCond %{REQUEST_FILENAME} !/maintenance.html
RewriteRule ^.*$ /maintenance.html [L]
</IfModule>
You can replace ^192\.3\.2\.1 with your IP while keeping the same format so you will still have full access.
Maintenance Mode via Terminal
You can also set the default version of Maintenance Mode with a single line via terminal.
Connect to your server using SSH.
Navigate to the root folder of your WordPress installation.
$ echo '<?php $upgrading = time(); ?>' > .maintenance
To disable maintenance mode, remove the .maintenance file using the rm command:
$ rm .maintenance
If you want to display a custom message, refer to the first option.
Keep Reading
We think you may like these
Free SVG QR Code Generator
No need to need to sign up, give away your email, or even pay just to download your QR code in a usable format like SVG.