Options -Indexes

# Never serve config, schema, docs, backups or env files
<FilesMatch "^(config\.php|db_export_lib\.php|auto_init\.php|provision_admin\.php|schema\.sql|.*\.md|.*\.bak|.*\.sql|\.env.*)$">
  Require all denied
</FilesMatch>

<IfModule mod_rewrite.c>
  RewriteEngine On
  # Shared hosting (CGI/FastCGI) strips the Authorization header -> every call after login returns 401.
  # This copies it into an environment variable that PHP can read.
  RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

  # Force HTTPS (308 keeps the POST body). Also honours proxies/CDNs to avoid redirect loops.
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC]
  RewriteCond %{HTTP_HOST} !^localhost(:\d+)?$ [NC]
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=308]
</IfModule>

<IfModule mod_setenvif.c>
  SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
</IfModule>
