Skip to content

Instantly share code, notes, and snippets.

@nilsbosman
Created March 15, 2021 18:29
Show Gist options
  • Save nilsbosman/32bb043597bda20582c741ae209fa3a1 to your computer and use it in GitHub Desktop.
Save nilsbosman/32bb043597bda20582c741ae209fa3a1 to your computer and use it in GitHub Desktop.
.htaccess - Maintenance mode with whitelisted IP's
# Rewrite url for maintenance mode
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^123\.456\.78\.90
RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
RewriteCond %{DOCUMENT_ROOT}/maintenance.true -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /maintenance.html [R=503,L]
ErrorDocument 503 /maintenance.html
</IfModule>
# Set headers
<IfModule mod_headers.c>
# 3600 = 60 minutes
# 86400 = 1 day
Header Set Cache-Control "max-age=0, no-store"
Header always set Retry-After "86400"
</IfModule>
@nilsbosman
Copy link
Author

If the maintenance.true file exists, all traffic will be redirected. I rename the file to maintenance.false for easy switching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment