-
Put
maintenance.html
into your root directory -
Open
.htaccess
file -
Insert this block in the first line of the file
ErrorDocument 503 /maintenance.html <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_URI} !=/maintenance.html RewriteCond %{REMOTE_ADDR} !=127.0.0.1 RewriteRule ^.*$ - [R=503,L] </IfModule>
-
Replace
127.0.0.1
to your ip address -
Done! Users except you will be redirected to maintenance.html
ErrorDocument 503 /maintenance.html
is when user gets error 503, redirect the page to maintenance.html
RewriteRule ^.*$ - [R=503,L]
does rewrite any url without replacing the url and access with 503
This was very useful! I am using this in my web servers. This solution requires no extra load on file system and does not require a restart of webserver to be activated. Good work!
One thing, though: If you have subfolders with their own .htaccess files with rewrite rules, you'll need this line in the root directory .htaccess to override the subfolder .htaccess rewrite rules: RewriteOptions InheritDownBefore
I spent some time before sorting this out, so I thought it'd be nice to get back to you with this info.