Skip to content

Instantly share code, notes, and snippets.

@Andy-set-studio
Created October 23, 2017 20:19
Show Gist options
  • Save Andy-set-studio/36b47b5fc4f6f3e65afa3d9d82f56ac0 to your computer and use it in GitHub Desktop.
Save Andy-set-studio/36b47b5fc4f6f3e65afa3d9d82f56ac0 to your computer and use it in GitHub Desktop.
.htaccess rules to place site in maintenance mode, but allow certain IP Address through
RewriteEngine On
# Allow through given IP Address
RewriteCond %{REMOTE_ADDR} !^95\.128\.11\.149
# Check for presence of Maintenance Page
RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
# Check for presence of enable file
RewriteCond %{DOCUMENT_ROOT}/maintenance.enable -f
# Allow common page assets through
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|css|js|svg|ico) [NC]
# Match against any request which isn't our maintenance page
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
# Rewrite the URL to our maintenance page
RewriteRule ^.*$ /maintenance.html [R=503,L]
# Set our maintenance page as the default page for 503 errors (maintenance mode)
ErrorDocument 503 /maintenance.html
# Prevent caching of maintenance page
Header Set Cache-Control "max-age=0, no-store"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment