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

    <Files .env>
        Order Allow,Deny
        Deny from all
    </Files>

    RewriteEngine On
    # Omit RewriteBase — Apache uses the directory URL prefix (works for root and subfolders).
    # If XAMPP POST routes fail under /clinic, copy .htaccess.xampp over this file.

    RewriteRule ^pwa-sw\.js$ public/pwa-sw.js [L,NC]

    # 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]

    # Legacy /storage URLs -> public/storage symlink
    RewriteCond %{REQUEST_URI} !\.\. [NC]
    RewriteRule ^storage/(.*)$ public/storage/$1 [L,NC]

    # Handle Front Controller...
    RewriteCond %{REQUEST_URI} !(\.css|\.js|\.json|\.lottie|\.png|\.jpg|\.jpeg|\.gif|\.webp|\.pdf|robots\.txt|\.ico|\.woff|\.woff2|.ttf|\.svg|\.webm|\.mp3|\.m4a|\.wav|\.ogg|\.oga|\.opus)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !^/public/
    RewriteRule ^(css|assets|market_assets|images|landing|uploads|installer|js|vendor|build|screenshots|pwa|animations)/(.*)$ public/$1/$2 [L,NC]
</IfModule>
