<IfModule mod_rewrite.c>
    Options -Indexes
    RewriteEngine On

    # Preserve Authorization header for APIs
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # If already under api/public, do nothing
    RewriteCond %{REQUEST_URI} ^/api/public/ [NC]
    RewriteRule ^ - [L]

    # Root request -> api/public/
    RewriteRule ^$ /api/public/ [L]

    # Forward everything else to Laravel's public folder
    RewriteRule ^(.*)$ /api/public/$1 [L,QSA]
</IfModule>
