
Options -Indexes
DirectoryIndex index.php login.php

RewriteEngine On
RewriteBase /operator/

# Nunca expor arquivos sensíveis (.env, .git, composer, vendor, migrations SQL/PHP diretas)
RewriteRule ^\.env$ - [F,L,NC]
RewriteRule ^\.git - [F,L,NC]
RewriteRule ^composer\.(json|lock)$ - [F,L,NC]
RewriteRule ^vendor - [F,L,NC]
RewriteRule ^database/migrations - [F,L,NC]

# Bloquear acesso direto à pasta credencial (PFX / certificados mTLS)
RewriteRule ^credencial/ - [F,L,NC]

# Entrada principal do Operator (raiz sem path)
RewriteRule ^$ index.php [L,QSA]

# Atalhos públicos para assets e imagens — NC = no case
RewriteRule ^assets/(.*)$ public/assets/$1 [L,QSA,NC]
RewriteRule ^img/(.*)$    public/img/$1    [L,QSA,NC]

# Se o arquivo ou diretório existe fisicamente, entrega direto
# (exceto /api /index.php?.. paths virtuais (ex: install.php em public/)
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# ================================================================
# QUALQUER rota /api/* (MESMO COM EXTENSÃO .csv / .json / etc)
# Cai no front controller.
#
# Frase-chave: não depender de REQUEST_URI prefixado com /operator/ no início
# (LiteSpeed no HostGator por vezes já remove RewriteBase e REQUEST_URI
# varia, por isso usamos NC + %{REQUEST_URI} e também o caminho relativo %{THE_REQUEST}
# ================================================================
RewriteCond %{REQUEST_URI} /api/ [NC,OR]
RewriteCond %{THE_REQUEST} \s/[^\s]*/api/ [NC]
RewriteRule ^ index.php [L,QSA]

# ================================================================
# Qualquer rota amigável (com ou sem / no meio) SEM arquivo físico)
# Usamos [^\.] como pattern antigo era frágil:
#   - Não cobria URLs com extensão .csv / .json (por isso a regra /api/ acima separada)
#   - Não aceita múltiplas barras / separador
# ================================================================
RewriteRule ^ index.php [L,QSA]
