# BLOQUEO DE IPS MALICIOSAS
<RequireAll>
    Require all granted
    Require not ip 37.27.51.140   
    Require not ip 20.5.74.70
    Require not ip 34.201.105.154
    Require not ip 47.91.65.23
    Require not ip 47.128.38.119
    Require not ip 144.76.19.70
</RequireAll>

<IfModule mod_rewrite.c>
    RewriteEngine On
    # Bloqueo estricto de bots por User Agent
    RewriteCond %{HTTP_USER_AGENT} (PetalBot|SERankingBacklinksBot) [NC]
    RewriteRule ^ - [F,L]
</IfModule>

# Bloqueamos peticiones .htm
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # Bloquea cualquier petición que termine exactamente en .htm    
    # R=503 lanza el estado Service Unavailable
    # L detiene el procesamiento de más reglas
    RewriteRule \.htm$ - [R=503,L,NC]
</IfModule>

# Desactivar documentos de error personalizados para evitar carga de PHP
ErrorDocument 403 "Prohibido - Acceso Denegado"

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # 2. Bloqueo de búsquedas ?s= en el Frontend
    # Condición: Si existe el parámetro 's' en la URL
    RewriteCond %{QUERY_STRING} (^|&)s=.* [NC]
    # Condición: Si NO es una petición al panel de control (backend)
    RewriteCond %{REQUEST_URI} !^/wp-admin [NC]
    # Condición: Si NO es una petición a archivos internos de sistema
    RewriteCond %{REQUEST_URI} !^/wp-includes [NC]
    
    # RESULTADO: 403 Forbidden y detener el procesamiento (L = Last)
    RewriteRule ^ - [F,L]
</IfModule>

# BEGIN LSCACHE
## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ##
<IfModule LiteSpeed>
RewriteEngine on
CacheLookup on
RewriteRule .* - [E=Cache-Control:no-autoflush]
RewriteRule litespeed/debug/.*\.log$ - [F,L]
RewriteRule \.litespeed_conf\.dat - [F,L]

### marker ASYNC start ###
RewriteCond %{REQUEST_URI} /wp-admin/admin-ajax\.php
RewriteCond %{QUERY_STRING} action=async_litespeed
RewriteRule .* - [E=noabort:1]
### marker ASYNC end ###

### marker DROPQS start ###
CacheKeyModify -qs:fbclid
CacheKeyModify -qs:gclid
CacheKeyModify -qs:utm*
CacheKeyModify -qs:_ga
### marker DROPQS end ###
</IfModule>

# Redirección a HTTPS (Optimizada)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

# BEGIN WordPress
# Las directivas (líneas) entre «BEGIN WordPress» y «END WordPress» son
# generadas dinámicamente y solo deberían ser modificadas mediante filtros de WordPress.
# Cualquier cambio en las directivas que hay entre esos marcadores serán sobrescritas.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^ca/wp-login.php /wp-login.php [QSA,L]
RewriteRule ^es/wp-login.php /wp-login.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

# Subir variables PHP (Añade esto para evitar los 404 en ajustes)
<IfModule mod_php8.c>
  php_value max_input_vars 5000
</IfModule>
SubstituteMaxLineLength 10M
# BEGIN LiteSpeed
# Las directivas (líneas) entre «BEGIN LiteSpeed» y «END LiteSpeed» son
# generadas dinámicamente y solo deberían ser modificadas mediante filtros de WordPress.
# Cualquier cambio en las directivas que hay entre esos marcadores serán sobrescritas.
<IfModule Litespeed>
	SetEnv noabort 1
</IfModule>
# END LiteSpeed