# Hebron Fire & Rescue Portal - Apache Configuration

# Force HTTPS
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Set default document
DirectoryIndex index.php index.html

# Security headers
<IfModule mod_headers.c>
    Header always set X-Content-Type-Options "nosniff"
    Header always set X-Frame-Options "SAMEORIGIN"
    Header always set X-XSS-Protection "1; mode=block"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# Deny access to sensitive files
<FilesMatch "\.(env|config|sql|md|sh)$">
    Order allow,deny
    Deny from all
</FilesMatch>

# Deny access to hidden files
<FilesMatch "^\.">
    Order allow,deny
    Deny from all
</FilesMatch>

# Allow .well-known for SSL
<IfModule mod_rewrite.c>
    RewriteRule ^\.well-known/ - [L]
</IfModule>

# PHP settings
<IfModule mod_php.c>
    php_value session.cookie_httponly 1
    php_value session.cookie_secure 1
    php_value session.use_strict_mode 1
</IfModule>

# Custom error pages
ErrorDocument 404 /404.php
ErrorDocument 403 /404.php

# Gzip compression for text assets
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/css application/javascript application/json text/plain text/xml application/xml
</IfModule>

# Browser caching for static assets
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css                   "access plus 1 week"
    ExpiresByType application/javascript     "access plus 1 week"
    ExpiresByType image/png                  "access plus 1 month"
    ExpiresByType image/jpeg                 "access plus 1 month"
    ExpiresByType image/gif                  "access plus 1 month"
    ExpiresByType image/svg+xml             "access plus 1 month"
    ExpiresByType image/webp                "access plus 1 month"
    ExpiresByType application/json           "access plus 5 minutes"
</IfModule>
