.htaccess忽略了RewriteCond [英] .htaccess is ignoring RewriteCond

查看:82
本文介绍了.htaccess忽略了RewriteCond的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下.htaccess。

I have the following .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,但是

Main part is the HTTPS redirect. I do not want to redirect robots.txt to https, but the

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

总是被忽略,并且robots.txt也重定向到https。

is always ignored and robots.txt is also redirected to https.

任何

推荐答案

此条件将始终返回false:

This condition will always return false:

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

这是因为在 / 之前的起始锚 ^ ,因为示例值 THE_REQUEST 是:

It is because of start anchor ^ before / since an example value of THE_REQUEST is:

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

因此相应地将您的条件更改为:

So accordingly change your condition to this:

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

并在新的浏览器中重新测试。

and retest in a new browser.

这篇关于.htaccess忽略了RewriteCond的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆