# ==========================================
# 1. CONFIGURACIÓN BÁSICA Y SEGURIDAD
# ==========================================

# Activar el motor de reescritura
RewriteEngine On

# Evitar que se liste el contenido de las carpetas
Options -Indexes

# Proteger archivos ocultos o sensibles (.env, .git, .htaccess, etc.)
<FilesMatch "^\.">
    Require all denied
</FilesMatch>


# ==========================================
# 2. ENRUTAMIENTO Y URLS AMIGABLES
# (Soluciona el filtrado de categorías)
# ==========================================

# Evitar que interfiera con archivos y carpetas reales existentes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Opción A: Si usas un archivo específico para categorías (ej. categoria.php?slug=nombre)
RewriteRule ^categoria/([a-zA-Z0-9_-]+)/?$ categoria.php?slug=$1 [L,QSA]

# Opción B (Alternativa): Si usas un enrutador centralizado (MVC / index.php)
# Descomenta la siguiente línea si toda tu web pasa por un index.php principal:
# RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]


# ==========================================
# 3. RENDIMIENTO Y COMPRESIÓN (GZIP)
# ==========================================

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json
</IfModule>


# ==========================================
# 4. CACHÉ DEL NAVEGADOR
# ==========================================

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/webp "access plus 1 month"
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
    ExpiresByType image/x-icon "access plus 1 year"
</IfModule>
<IfModule mod_rewrite.c>

    RewriteEngine On
 
    # ---- INICIO: Página de producto con URL amigable ----
    # Convierte:  /producto/mi-producto-45
    # en:         producto.php?slug=mi-producto-45
    RewriteRule ^producto/([a-zA-Z0-9\-]+)/?$ producto.php?slug=$1 [L,QSA,NC]
    # ---- FIN: Página de producto con URL amigable ----
</IfModule>
 