RewriteEngine On

# Many shared-hosting stacks (PHP-FPM, LiteSpeed, suPHP/CGI) drop the
# Authorization header before it reaches PHP. This re-injects it as an
# environment variable so getallheaders()/HTTP_AUTHORIZATION keep working.
<IfModule mod_rewrite.c>
    RewriteCond %{HTTP:Authorization} ^(.*)
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%1]
</IfModule>
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
<IfModule mod_version.c>
    <IfVersion >= 2.4>
        CGIPassAuth On
    </IfVersion>
</IfModule>

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME}.php -f

RewriteRule ^([^/]+)$ $1.php [L]

RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]

RewriteRule ^ /%1 [R=301,L]
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
