# Impede listagem e permite rewrites
Options -Indexes +FollowSymLinks
RewriteEngine On

# Não permitir acesso direto a arquivos .*
<FilesMatch "^\.">
  Require all denied
</FilesMatch>

# Proteger index.php (não mostrar o arquivo na URL)
<IfModule mod_rewrite.c>
  # Se existir um arquivo ou diretório, serve-o direto
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  # Senão, envia para o front controller do Laravel
  RewriteRule ^ index.php [L]
</IfModule>

# Segurança extra para tipos executáveis
<FilesMatch "^(?!index\.php$).*\.(php|phtml|phar)$">
  Require all denied
</FilesMatch>

# -------------------------------
# Performance: compressão/cache
# -------------------------------
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript application/json application/xml application/rss+xml application/atom+xml image/svg+xml
  Header append Vary Accept-Encoding
</IfModule>

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/avif "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/png  "access plus 1 year"
  ExpiresByType image/gif  "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"

  ExpiresByType font/woff2 "access plus 1 year"
  ExpiresByType font/woff  "access plus 1 year"
  ExpiresByType font/ttf   "access plus 1 year"
  ExpiresByType font/otf   "access plus 1 year"

  ExpiresByType text/css "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"

  ExpiresByType text/html "access plus 5 minutes"
</IfModule>

<IfModule mod_headers.c>
  <FilesMatch "\.(avif|webp|jpe?g|png|gif|svg|woff2?|ttf|otf)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
  </FilesMatch>
  <FilesMatch "\.(css|js)$">
    Header set Cache-Control "public, max-age=2592000"
  </FilesMatch>
  <FilesMatch "\.(html?|json)$">
    Header set Cache-Control "no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires "0"
  </FilesMatch>
</IfModule>
