# ── HTTPS redirect ──────────────────────────────────────
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# ── React SPA en subdirectorio /litoralwebia/ ────────────
RewriteBase /litoralwebia/

# No reescribir archivos/directorios reales
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# No reescribir rutas a la API PHP
RewriteCond %{REQUEST_URI} !^/litoralwebia/api/
# Todo lo demás → index.html
RewriteRule . /litoralwebia/index.html [L]

# ── Seguridad ────────────────────────────────────────────
# Bloquear archivos de configuracion interna (solo exactamente estos nombres)
<FilesMatch "^(config|db)\.php$">
    Order allow,deny
    Deny from all
</FilesMatch>
# Bloquear archivos ocultos (.htaccess, .env, etc.)
<FilesMatch "^\.">
    Order allow,deny
    Deny from all
</FilesMatch>

<IfModule mod_headers.c>
    Header always set X-Frame-Options "SAMEORIGIN"
    Header always set X-Content-Type-Options "nosniff"
    # Cache agresivo para assets con hash en el nombre
    <FilesMatch "\.(js|css|png|jpg|jpeg|gif|ico|svg|woff2?)$">
        Header set Cache-Control "max-age=31536000, public, immutable"
    </FilesMatch>
    # No cachear el HTML (SPA entry point)
    <FilesMatch "\.html$">
        Header set Cache-Control "no-cache, no-store, must-revalidate"
    </FilesMatch>
</IfModule>

# ── PHP config ──────────────────────────────────────────
<IfModule mod_php8.c>
    php_flag display_errors Off
</IfModule>
