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

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

    # Handle API requests
    RewriteCond %{REQUEST_URI} ^/api/.*
    RewriteRule ^ index.php [L]

    # Handle Installer
    RewriteCond %{REQUEST_URI} ^/install.*
    RewriteRule ^ index.php [L]

    # Send Requests To Frontend App (React)
    # If the file or directory exists, serve it
    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]

    # Otherwise, send it to index.html for React routing
    RewriteRule ^ index.html [L]
</IfModule>
