Php 不允许通过.htaccess访问根目录中的txt文件

Php 不允许通过.htaccess访问根目录中的txt文件,php,.htaccess,Php,.htaccess,我有定制的MVC框架,我的.htaccess文件重写规则,通过index.php发送所有请求,然后通过index.php路由请求 RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-l RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !\.(css|js|jpg|jpeg|JPG|gif|png|P

我有定制的MVC框架,我的.htaccess文件重写规则,通过index.php发送所有请求,然后通过index.php路由请求

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.(css|js|jpg|jpeg|JPG|gif|png|PNG|ico|pdf|swf|xml|pem)$ [NC]
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

问题是,在index.php和
.htaccess
所在的公共html文件夹中有一些.txt文件。是否可以不允许用户访问.txt文件?现在如果我访问
www.MyURL/test.txt
,我可以查看txt文件。但是如果我这样做了,www.MyURL/cont/action/param1将正常工作。

您可以使用以下方法阻止所有
.txt
文件:

RewriteEngine on

RewriteRule \.txt$ - [F,NC]

RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.(css|js|jpg|jpeg|JPG|gif|png|PNG|ico|pdf|swf|xml|pem)$ [NC]
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

您可以使用以下方法阻止所有
.txt
文件:

RewriteEngine on

RewriteRule \.txt$ - [F,NC]

RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.(css|js|jpg|jpeg|JPG|gif|png|PNG|ico|pdf|swf|xml|pem)$ [NC]
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]