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

    <Files .env>
        order allow,deny
        Deny from all
    </Files>

    RewriteEngine On

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

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

    # ✅ Serve .well-known files directly from public/assets/.well-known
    RewriteCond %{REQUEST_URI} ^/\.well-known/ [NC]
    RewriteRule ^\.well-known/(.*)$ public/assets/$1 [L]

    # ✅ Exclude static assets from Laravel routing
    RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.jpeg|\.gif|\.ico|\.woff|\.woff2|\.ttf|\.svg|robots\.txt)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f

    # ✅ Send all other requests to Laravel
    RewriteRule ^ index.php [L]

    # ✅ Map Laravel public subdirectories (css, assets, js, etc.)
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !^/public/
    RewriteRule ^(css|js|images|storage|assets|landing|installer)/(.*)$ public/$1/$2 [L,NC]
</IfModule>
