# ============================================
# FORÇA HTTPS
# ============================================

RewriteEngine On

# Redireciona HTTP para HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# ============================================
# PERMITE AUTHORIZATION HEADER
# ============================================

# Captura Authorization header e coloca em variável de ambiente
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [E=HTTP_AUTHORIZATION:%1]

# Alternativa (se a de cima não funcionar)
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

# ============================================
# SEGURANÇA GERAL
# ============================================

# Desabilita listagem de diretórios
Options -Indexes

# Bloqueia acesso a arquivos sensíveis
<FilesMatch "^\.">
    Order allow,deny
    Deny from all
</FilesMatch>

# Protege .env
<Files ".env">
    Order allow,deny
    Deny from all
</Files>

# Headers de segurança
<IfModule mod_headers.c>
    # Protege contra XSS
    Header set X-Content-Type-Options "nosniff"
    Header set X-Frame-Options "SAMEORIGIN"
    Header set X-XSS-Protection "1; mode=block"
    
    # Remove assinatura do servidor
    Header unset Server
    Header unset X-Powered-By
</IfModule>

# ============================================
# PERMISSÕES DE ARQUIVOS PHP
# ============================================

# Permite acesso aos endpoints PHP
<FilesMatch "\.php$">
    Order allow,deny
    Allow from all
</FilesMatch>