# INDPLS.in - Indianapolis Community Portal
# Apache Configuration

RewriteEngine On

# Force HTTPS (uncomment for production)
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Block access to sensitive directories
RewriteRule ^config/ - [F,L]
RewriteRule ^data/ - [F,L]
RewriteRule ^includes/ - [F,L]
RewriteRule ^templates/ - [F,L]
RewriteRule ^content/ - [F,L]
RewriteRule ^cron/ - [F,L]

# Block hidden files and sensitive extensions
<FilesMatch "^\.">
    Require all denied
</FilesMatch>

<FilesMatch "\.(json|sqlite|db|log|sh|md)$">
    Require all denied
</FilesMatch>

# Allow specific public files
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(index\.php|dashboard\.php)$ - [L]

# Allow assets directory
RewriteCond %{REQUEST_URI} ^/assets/
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

# Allow API directory
RewriteCond %{REQUEST_URI} ^/api/
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

# Route everything else through index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]

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

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

# Cache static assets
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/webp "access plus 1 month"
    ExpiresByType image/svg+xml "access plus 1 month"
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
</IfModule>

# PHP settings (if allowed)
<IfModule mod_php.c>
    php_value upload_max_filesize 10M
    php_value post_max_size 10M
</IfModule>
