# API URL rewrite — converts /api/<path> into /api/index.php?url=<path>
# and forwards the Authorization header to PHP (Plesk/Apache strip it
# by default when running PHP-FPM behind the front-end server).

RewriteEngine On

# Pass the Authorization header through to PHP. PHP exposes it via the
# HTTP_AUTHORIZATION env var, which $general->getBasicAuthorizationData()
# reads. Without this rewrite, Plesk's Apache→PHP-FPM proxy drops it
# and every auth call returns "Authorization not found".
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [E=HTTP_AUTHORIZATION:%1]

# Skip the rewrite for actual files and directories so existing assets
# (system/, etc.) keep serving directly.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Route everything else through index.php. QSA preserves any extra
# query parameters; L stops further rewriting.
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
