Options -Indexes

RewriteEngine On
RewriteBase /painel/

# Forca HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# /painel/login -> /painel/ (compatibilidade com cache antigo)
RewriteCond %{THE_REQUEST} \s/painel/login(\.php)?[\s?]
RewriteRule ^login(\.php)?$ /painel/ [R=301,L,NE]

# /painel/index e /painel/index.php -> /painel/ (301)
RewriteCond %{THE_REQUEST} \s/painel/index(\.php)?[\s?]
RewriteRule ^index(\.php)?$ /painel/ [R=301,L,NE]

# /painel/home serve panel.php internamente
RewriteRule ^home$ panel.php [L,QSA]

# Remove .php -- apenas GET diretos
RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{THE_REQUEST} ^GET\s/painel/([^?\s]+)\.php[?\s]
RewriteRule ^ /painel/%1 [R=301,L,NE,QSA]

# Serve .php internamente para URLs sem extensao
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ $1.php [L,QSA]

# Bloqueia acesso a arquivos sensiveis (compativel Apache 2.2 e 2.4)
<FilesMatch "(error_log|db_config\.php|config\.local\.php|\.bak|\.log|\.sql|\.env)$">
    Order Allow,Deny
    Deny from all
</FilesMatch>
