# ----------------------------------------------------------------------
# Liceo Pequenos Duendes — configuracion para hosting Apache / cPanel
# Sube este archivo junto al resto del contenido (debe quedar en la misma
# carpeta que index.html). Si tu hosting usa Nginx, este archivo se ignora:
# pide al soporte un "try_files $uri $uri/ /index.html;".
# ----------------------------------------------------------------------

Options -Indexes
AddDefaultCharset UTF-8
DirectoryIndex index.html

# --- Enrutado del sitio (Single Page Application) ----------------------
# Cualquier URL que no corresponda a un archivo real sirve index.html,
# para que el enrutador de la web responda tambien en enlaces directos.
<IfModule mod_rewrite.c>
  RewriteEngine On

  # Carpeta donde vive la web dentro del dominio. Debe coincidir con el valor
  # de "base" en vite.config.ts. Si la web esta en la raiz del dominio,
  # deja esta linea comentada con #.
  RewriteBase /liceopequenosduendes/

  # Forzar HTTPS: DESACTIVADO por defecto para evitar bucles de redireccion.
  # Cuando tu dominio ya tenga certificado SSL y cargue bien por https,
  # quita el # de las tres lineas siguientes.
  # RewriteCond %{HTTPS} !=on
  # RewriteCond %{HTTP:X-Forwarded-Proto} !=https
  # RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  # No reescribir archivos ni carpetas que existen de verdad
  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^ - [L]

  # Todo lo demas va al index
  RewriteRule ^ index.html [L]
</IfModule>

# --- Compresion --------------------------------------------------------
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml
  AddOutputFilterByType DEFLATE application/javascript application/json
  AddOutputFilterByType DEFLATE image/svg+xml
</IfModule>

# --- Cache -------------------------------------------------------------
<IfModule mod_expires.c>
  ExpiresActive On

  # Los archivos de /assets llevan un hash en el nombre: cache larga y segura
  <FilesMatch "\.(js|css|woff2|woff|ttf|webp|avif|png|jpe?g|gif|svg|ico)$">
    ExpiresDefault "access plus 1 year"
    Header set Cache-Control "public, max-age=31536000, immutable"
  </FilesMatch>

  # El HTML nunca se cachea, asi los cambios se ven al instante
  <FilesMatch "\.html$">
    ExpiresDefault "access plus 0 seconds"
    Header set Cache-Control "no-cache, must-revalidate"
  </FilesMatch>
</IfModule>

# --- Tipos MIME (algunos hostings antiguos no los traen) ---------------
<IfModule mod_mime.c>
  AddType image/webp .webp
  AddType image/avif .avif
  AddType font/woff2 .woff2
  AddType application/json .json
</IfModule>

# --- Cabeceras de seguridad basicas ------------------------------------
<IfModule mod_headers.c>
  Header set X-Content-Type-Options "nosniff"
  Header set Referrer-Policy "strict-origin-when-cross-origin"
  Header set X-Frame-Options "SAMEORIGIN"
</IfModule>
