【问题标题】:.htaccess: prevent access to files and prevent directory browsing.htaccess:阻止访问文件并阻止目录浏览
【发布时间】:2011-09-16 18:51:58
【问题描述】:

我想阻止所有文件访问和目录浏览,而不在所述目录中放置 .htaccess 文件。

例如,假设这是在我的网络根目录中:

.htaccess
索引.php
我的框架/

我在那个 .htaccess 文件中放了什么,这样每当有人浏览 myframework/ 中的目录或文件时,他们都会得到 403 禁止。

现在我所做的只是Options All -Indexes,但这只会阻止目录浏览 - 如果他们知道myframework/ 中的确切文件 URL,那么他们仍然可以浏览到该文件。

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite


    【解决方案1】:

    启用 mod_rewrite

    $ sudo a2enmod rewrite
    

    将此附加到您的 .htaccess;

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteRule ^myframework/ - [F,L]
    </IfModule>
    

    【讨论】:

      【解决方案2】:

      在您的 DOCUMENT_ROOT .htaccess 文件中包含此代码

      Options +FollowSymlinks -MultiViews
      
      RewriteEngine On
      RewriteRule ^myframework/ - [NC,F,L]
      
      • NC - 忽略大小写比较
      • F - 将当前 URI 标记为禁止
      • L - 将此规则标记为最后一条

      【讨论】:

        猜你喜欢
        • 2012-08-22
        • 2011-09-26
        • 1970-01-01
        • 2011-01-28
        • 2014-11-17
        • 2023-04-01
        • 2012-07-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多