<IfModule mod_rewrite.c>
    RewriteEngine On
    # RewriteBase /

    # Pass Authorization header to PHP (Apache mod_fcgid strips it by default)
    RewriteCond %{HTTP:Authorization} .+
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # If the requested file or directory exists, serve it directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    # Route everything else through the front controller
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

# Set default charset
AddDefaultCharset UTF-8

# Security headers for static assets
<IfModule mod_headers.c>
    # Strip engine/framework version disclosures globally
    Header unset X-Powered-By

    # Apply standard security headers ONLY to static assets to avoid duplication with PHP middleware headers
    <FilesMatch "\.(css|js|gif|jpg|jpeg|png|svg|ico|webp|woff2|woff)$">
        Header set X-Content-Type-Options "nosniff"
        Header set X-Frame-Options "DENY"
        Header set Referrer-Policy "strict-origin-when-cross-origin"
    </FilesMatch>
</IfModule>

# Cache static assets (1 year)
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
    ExpiresByType image/webp "access plus 1 year"
    ExpiresByType font/woff2 "access plus 1 year"
    ExpiresByType font/woff "access plus 1 year"
    ExpiresByType application/font-woff2 "access plus 1 year"
</IfModule>

# Compress text-based assets
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/css application/json application/javascript text/xml
</IfModule>
