.htaccess ignora RewriteCond

Oct 22 2019

Tengo el siguiente .htaccess.

RewriteEngine On

# HTTPS redirect
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{THE_REQUEST} !^/robots.txt [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [L] RewriteRule ^(.+)$  /index.php [L,QSA]

La parte principal es la redirección HTTPS. No quiero redirigir robots.txt a https, pero el

RewriteCond %{THE_REQUEST} !^/robots.txt [NC]

siempre se ignora y robots.txt también se redirige a https.

¿Alguna idea de lo que puede estar mal?

Respuestas

anubhava Oct 22 2019 at 10:50

Esta condición siempre devolverá falso:

RewriteCond %{THE_REQUEST} !^/robots.txt [NC]

Es debido al ancla de inicio ^anterior, /ya que un valor de ejemplo de THE_REQUESTes:

GET /index.php?id=123 HTTP/1.1

Entonces, en consecuencia, cambie su condición a esto:

RewriteCond %{THE_REQUEST} !^[A-Z]{3,}\s/+robots\.txt\s [NC]

y vuelva a probar en un nuevo navegador.