# =============================================================
#  MedNord — .htaccess para cPanel
#  Ativar/desativar o redirect HTTPS conforme necessário.
# =============================================================

# ── HTTPS redirect (ativar após instalar certificado SSL) ──
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# ── Remove www (opcional — mantenha apenas uma versão) ──
# RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
# RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]

# ── URLs limpas (sem .html) ──
# index.html -> raiz do site
RewriteRule ^index\.html$ / [R=301,L]

# qualquer-pagina.html -> qualquer-pagina (redirect visível na barra de endereços)
RewriteCond %{THE_REQUEST} \s/+([^.\s]+)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=301,L]

# serve internamente o .html quando o pedido não tem extensão
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^.]+)$ $1.html [NC,L]

# ── Gzip / Deflate ──
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript
  AddOutputFilterByType DEFLATE application/javascript application/x-javascript
  AddOutputFilterByType DEFLATE application/json image/svg+xml font/woff2 font/woff
</IfModule>

# ── Cache de browser ──
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault                         "access plus 1 month"
  ExpiresByType text/html                "access plus 1 day"
  ExpiresByType text/css                 "access plus 3 months"
  ExpiresByType application/javascript   "access plus 3 months"
  ExpiresByType image/jpeg               "access plus 1 year"
  ExpiresByType image/jpg                "access plus 1 year"
  ExpiresByType image/png                "access plus 1 year"
  ExpiresByType image/webp               "access plus 1 year"
  ExpiresByType image/gif                "access plus 1 year"
  ExpiresByType image/svg+xml            "access plus 1 year"
  ExpiresByType image/x-icon             "access plus 1 year"
  ExpiresByType font/woff2               "access plus 1 year"
  ExpiresByType font/woff                "access plus 1 year"
</IfModule>

# ── Cache-Control headers ──
<IfModule mod_headers.c>
  <FilesMatch "\.(jpg|jpeg|png|gif|webp|svg|ico|woff2|woff)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
  </FilesMatch>
  <FilesMatch "\.(css|js)$">
    Header set Cache-Control "public, max-age=7776000"
  </FilesMatch>
  <FilesMatch "\.html$">
    Header set Cache-Control "public, max-age=86400"
  </FilesMatch>

  # Segurança
  Header always set X-Frame-Options "SAMEORIGIN"
  Header always set X-Content-Type-Options "nosniff"
  Header always set Referrer-Policy "strict-origin-when-cross-origin"
  Header always set X-XSS-Protection "1; mode=block"
  Header always set Permissions-Policy "camera=(), microphone=(), geolocation=()"
</IfModule>

# ── Sem listagem de diretórios ──
Options -Indexes

# ── Página 404 → index ──
ErrorDocument 404 /index.html
