我有以下.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]
主要部分是HTTPS重定向。我不想将robots.txt重定向到https,但是
RewriteCond %{THE_REQUEST} !^/robots.txt [NC]
始终被忽略,并且robots.txt也重定向到https。
有什么主意吗?
答案 0 :(得分:0)
此条件将始终返回false:
RewriteCond %{THE_REQUEST} !^/robots.txt [NC]
这是因为^
的示例值是/
之前的起始锚点THE_REQUEST
:
GET /index.php?id=123 HTTP/1.1
因此,请相应地更改您的条件:
RewriteCond %{THE_REQUEST} !^[A-Z]{3,}\s/+robots\.txt\s [NC]
并在新的浏览器中重新测试。