我有自定义MVC框架,我的.htaccess文件重写规则,通过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]
问题是我在public_html文件夹中有一些 .txt 文件,其中包含index.php和.htaccess
。是否有可能不允许用户访问.txt文件?现在如果我访问www.MyURL/test.txt
我可以查看txt文件。但如果我www.MyURL/cont/action/param1
可以正常工作。
答案 0 :(得分:4)
您可以使用以下方法阻止所有.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]