# ============================================================================
# .htaccess de oposicionesaguardiacivil.com — GENERADO por el kit (site-kit/htaccess.njk).
# No lo edites a mano: se regenera en cada build con el dominio de provincias.csv.
# Va en la carpeta raíz del dominio en el hosting (public_html).
# ============================================================================

# --- 1) Un solo dominio canónico: https + sin www -------------------------------
# Cada regla redirige en UN salto (sin cadenas). Se excluye .well-known para no
# romper la renovación automática del certificado SSL (AutoSSL / Let's Encrypt).
<IfModule mod_rewrite.c>
RewriteEngine On

# /index.html (y /ruta/index.html) -> /  y  /ruta/   (cualquier protocolo o www)
RewriteCond %{REQUEST_URI} !^/\.well-known/
RewriteCond %{THE_REQUEST} \s/+(.*/)?index\.html[\s?] [NC]
RewriteRule ^(.*/)?index\.html$ https://oposicionesaguardiacivil.com/$1 [R=301,L]

# http -> https (el condicional del proxy evita bucles detrás de un CDN)
RewriteCond %{REQUEST_URI} !^/\.well-known/
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://oposicionesaguardiacivil.com%{REQUEST_URI} [R=301,L]

# www -> sin www
RewriteCond %{REQUEST_URI} !^/\.well-known/
RewriteCond %{HTTP_HOST} ^www\.oposicionesaguardiacivil\.com$ [NC]
RewriteRule ^ https://oposicionesaguardiacivil.com%{REQUEST_URI} [R=301,L]
</IfModule>

# --- 2) Página 404 propia (con estado HTTP 404 real) ---------------------------
ErrorDocument 404 /404.html

# --- 3) Codificación y tipos de archivo ----------------------------------------
AddDefaultCharset UTF-8
<IfModule mod_mime.c>
AddType application/manifest+json .webmanifest
AddType image/webp .webp
AddType application/xslt+xml .xsl
</IfModule>

# --- 4) Cabeceras de seguridad y caché del HTML --------------------------------
<IfModule mod_headers.c>
# HSTS: empieza con 1 día (86400 s). Cuando compruebes que todo funciona por https,
# sube el valor a 31536000 (1 año) en site.json -> "hstsSeconds".
Header always set Strict-Transport-Security "max-age=86400"
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "SAMEORIGIN"
Header always set Referrer-Policy "strict-origin-when-cross-origin"

# El HTML se revalida siempre (304 si no ha cambiado): las actualizaciones se ven al momento.
<FilesMatch "\.html$">
Header set Cache-Control "public, max-age=0, must-revalidate"
</FilesMatch>
</IfModule>
