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

    RewriteEngine On

    # Only the root front controller should be reachable as a PHP script.
    RewriteRule "(^|/)\.(?!well-known(?:/|$))" - [F]
    RewriteRule "^(?!index\.php(?:/|$)).*\.(?:php[0-9]*|phtml|phar)(?:[./]|$)" - [F,NC]

    # Pass the Bearer token through to PHP on Apache (otherwise every API call is 401)
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

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

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
