【问题标题】:Dont allow access to txt files in root via .htaccess不允许通过 .htaccess 访问根目录下的 txt 文件
【发布时间】:2014-05-19 15:10:35
【问题描述】:

我有自定义 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]

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

【问题讨论】:

    标签: php .htaccess


    【解决方案1】:

    您可以使用以下命令阻止所有 .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]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-02
      • 2011-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-03
      • 2010-11-16
      相关资源
      最近更新 更多