<IfModule mod_rewrite.c>
    RewriteEngine On

    # Força remoção do www (www.exemplo.com → exemplo.com)
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]
    
    # Redireciona HTTP para HTTPS
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    # Route 404s to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
    RewriteRule (.+) index.php [L]
</IfModule>

# ===== Cache de estáticos (performance / Lighthouse) =====
<IfModule mod_headers.c>
    # Imagens, vídeo e fontes: conteúdo estável → 1 ano, imutável
    <FilesMatch "\.(jpe?g|png|gif|webp|svg|ico|mp4|webm|ogg|woff2?|ttf|otf|eot)$">
        Header set Cache-Control "public, max-age=31536000, immutable"
    </FilesMatch>

    # CSS / JS: não versionados (sem ?v=) → 7 dias com revalidação,
    # para não servir versões antigas após um deploy
    <FilesMatch "\.(css|js)$">
        Header set Cache-Control "public, max-age=604800, stale-while-revalidate=86400"
    </FilesMatch>
</IfModule>

# Fallback caso mod_headers não esteja disponível (define Expires + max-age)
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpeg                "access plus 1 year"
    ExpiresByType image/png                 "access plus 1 year"
    ExpiresByType image/gif                 "access plus 1 year"
    ExpiresByType image/webp                "access plus 1 year"
    ExpiresByType image/svg+xml             "access plus 1 year"
    ExpiresByType image/x-icon              "access plus 1 year"
    ExpiresByType video/mp4                 "access plus 1 year"
    ExpiresByType video/webm                "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 application/vnd.ms-fontobject "access plus 1 year"
    ExpiresByType text/css                  "access plus 7 days"
    ExpiresByType application/javascript    "access plus 7 days"
    ExpiresByType text/javascript           "access plus 7 days"
</IfModule>

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php83” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php83 .php .php8 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
