# /etc/apache2/conf-available/zz_maintenance.conf
# Global maintenance switch: rewrites all requests to /maintenance.html
# Requires mod_rewrite and mod_alias.

<IfModule mod_rewrite.c>
    RewriteEngine On

    # 1) Return 500 for dangerous/alias paths (beispiel: /icons, /server-status, /private)
    #    Passe die Liste in Klammern nach Bedarf an.
    RewriteCond %{REQUEST_URI} ^/(icons|server-status|private|.*/icons)(/|$) [NC]
    RewriteRule ^ - [R=500,L]

    # 2) Allow direct access to the maintenance document itself (avoid rewrite loop)
    RewriteCond %{REQUEST_URI} ^/maintenance.html$ [NC]
    RewriteRule ^ - [L]

    # 3) Rewrite everything else internally to /maintenance.html
    #    We use an internal rewrite (no external redirect) so Host stays the same.
    RewriteRule ^/(.*)$ /maintenance.html [L]
</IfModule>

# Map the maintenance page to the filesystem
Alias /maintenance.html /var/www/maintenance/maintenance.html
<Directory /var/www/maintenance>
    Require all granted
    Options -Indexes
</Directory>

# Return a short 503 body for other errors (optional)
ErrorDocument 500 "Internal Server Error - service temporarily unavailable"
ErrorDocument 503 /maintenance.html

