<IfModule mod_rewrite.c>
  RewriteEngine On

  # REDIRECCIONAR TODO A HTTPS (OBLIGATORIO EN PRODUCCIÓN)
  RewriteCond %{HTTPS} off
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  # REDIRIGIR NO-WWW A WWW (para al URL final es con www, tal como solicitaste)
  RewriteCond %{HTTP_HOST} ^tecnocrass\.com$ [NC]
  RewriteRule ^(.*)$ https://www.tecnocrass.com%{REQUEST_URI} [R=301,L]

  # SALTARSE EL REWRITE SI EL ARCHIVO PHP REALMENTE EXISTE (ej: test_conexion.php)
  RewriteCond %{REQUEST_FILENAME} -f
  RewriteRule \.php$ - [L]

  RewriteRule ^$ public/ [L]
  RewriteRule (.*) public/$1 [L]
</IfModule>

# HEADERS DE SEGURIDAD PARA PRODUCCIÓN
<IfModule mod_headers.c>
  # Protección contra ataques Clickjacking
  Header always set X-Frame-Options "SAMEORIGIN"
  # Prevenir MIME sniffing
  Header always set X-Content-Type-Options "nosniff"
  # Protección XSS básica
  Header always set X-XSS-Protection "1; mode=block"
  # Política de referencia
  Header always set Referrer-Policy "strict-origin-when-cross-origin"
  # Forzar conexión segura HTTPS durante 1 año
  Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains" env=HTTPS
</IfModule>

# OCULTAR VERSIÓN DE APACHE (pequeña mejora de seguridad)
ServerTokens Prod
ServerSignature Off
