# Enable Apache's mod_rewrite
RewriteEngine On

# Set a custom error document for 503 Service Unavailable responses
ErrorDocument 503 /maintenance/

# Whitelist a specific IP address (replace with your actual public IP)
RewriteCond %{REMOTE_ADDR} ^162\.0\.235\.187$
RewriteRule .* - [L]

# Activate maintenance mode if the maintenance.flag file exists:
# - Check for the maintenance.flag file in the document root.
# - Prevent a redirection loop by excluding requests that are already for the maintenance folder.
RewriteCond %{DOCUMENT_ROOT}/maintenance.flag -f
RewriteCond %{REQUEST_URI} !^/maintenance/ [NC]
RewriteRule ^(.*)$ /maintenance/ [R=503,L]
