<IfModule mod_rewrite.c>
    RewriteEngine On

    # Fix for Authorization headers
    RewriteCond %{HTTP:Authorization} ^(.*)
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%1]

    # Remove trailing slash
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Skip existing files/folders
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]

    # Support static assets in public/build/
    RewriteRule ^build/(.*)$ build/$1 [L]

    # Fallback to index.php for all other routes
    RewriteRule ^ index.php [L]
</IfModule>
