<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Handle X-XSRF-Token Header
    RewriteCond %{HTTP:x-xsrf-token} .
    RewriteRule .* - [E=HTTP_X_XSRF_TOKEN:%{HTTP:X-XSRF-Token}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

<IfModule mod_mime.c>
    AddType application/manifest+json .json
    AddType application/javascript .js
    AddType image/png .png
</IfModule>

<IfModule mod_headers.c>
    <Files "manifest.json">
        Header set Content-Type "application/manifest+json"
        Header set Cache-Control "no-cache"
    </Files>
    <Files "sw.js">
        Header set Content-Type "application/javascript"
        Header set Cache-Control "no-cache, no-store, must-revalidate"
    </Files>
    <Files "offline.html">
        Header set Cache-Control "no-cache"
    </Files>
</IfModule>

# Block access to sensitive files in public
<FilesMatch "^(\.env|\.git|composer)">
    Require all denied
</FilesMatch>

# Block access to storage logs
<IfModule mod_rewrite.c>
    RewriteRule ^storage/logs/ - [F,L]
</IfModule>
