# ============================================================
# HTSPanamá — .htaccess
# ============================================================
# El panel de Namecheap SSL ya gestiona "HTTPS Redirect: On",
# por eso aquí NO redirigimos HTTPS ni www (lo hace el panel).
# ============================================================

RewriteEngine On

# --- 0) NUNCA reescribir/redirigir la carpeta includes/ (APIs internas como chat.php) ---
# El chatbot hace fetch('includes/chat.php') por POST; sin esta excepción, la regla 1
# de abajo lo redirigiría (301) y rompería la llamada -> el bot caería a las reglas.
RewriteRule ^includes/ - [L]

# --- 1) Si alguien entra con .php, redirige a la URL limpia (sin .php) ---
# Ej: /services.php  ->  /services    |    /index.php -> /
# El flag QSA preserva el ?lang=es si lo hubiera
RewriteCond %{THE_REQUEST} \s/+([^.\s?]+)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE,QSA]

# Caso especial: index -> raíz (/)
RewriteCond %{THE_REQUEST} \s/+index\.php[\s?] [NC]
RewriteRule ^ / [R=301,L]
RewriteRule ^index/?$ / [R=301,L]

# --- 2) Internamente, sirve el .php sin mostrarlo ---
# Ej: el visitante ve /services y el servidor carga services.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([a-zA-Z0-9_-]+)/?$ $1.php [L]

# --- AI chatbot (opcional): descomenta y pon tu API key ---
# SetEnv ANTHROPIC_API_KEY sk-ant-xxxxx

# --- Seguridad básica de cabeceras ---
<IfModule mod_headers.c>
    Header always set X-Content-Type-Options "nosniff"
    Header always set X-Frame-Options "SAMEORIGIN"
</IfModule>
