【问题标题】:Deny access to multiple files in htaccess拒绝访问 htaccess 中的多个文件
【发布时间】:2012-09-23 23:07:40
【问题描述】:

我想通过 htaccess 拒绝多个文件。

<FilesMatch (profile|reg|register|..............|)\.php>
order allow,deny
deny from all
</FilesMatch>

我有很多文件(6 个文件夹,每个文件夹大约 30 个文件)我想拒绝访问,因此使用上述方法逐个输入它们需要时间。

我可以拒绝访问此类文件夹中的所有文件吗?

<Directory /www/php/login/pages>
  Order Allow,Deny
</Directory>

【问题讨论】:

  • 手册无所不知:<Directory> Directive
  • 是的,当然可以。另外,如果您拒绝访问这些脚本,为什么还要将它们放在 Web 根目录中?通常的做法是只将需要的内容放在 Web 根目录中,而将应用程序的其余部分留在其他地方。
  • 最好的解决方案是简单地将这些文件放在文档根目录之外。 php 仍然可以包含/需要它们,因为它不受 apache 级别的限制。

标签: php html file .htaccess


【解决方案1】:

您需要像最初的方法一样添加“全部拒绝”,但是可以。

在文档中向下滚动您要查找的语法:http://httpd.apache.org/docs/2.2/mod/core.html#directory

【讨论】:

  • 从您引用的页面:Note that unlike &lt;Directory&gt; and &lt;Location&gt; sections, &lt;Files&gt; sections can be used inside .htaccess files. ==> .htaccess 中没有
【解决方案2】:

多个

<FilesMatch "(foo|bar|doo)\.php$">
    Deny from all
</FilesMatch>

或者去重写规则 (RewriteEngine On)

RewriteRule \.(psd|log)$ - [NC,F]

拒绝访问文件夹中的所有文件:

rewriteRule ^www/php/login/pages - [NC,F]

或者直接在该文件夹中放置一个“全部拒绝”...

2015 年更新:使用 Apache 2.4 或更高版本,“拒绝所有人”would needs adjustment

【讨论】:

    猜你喜欢
    • 2011-05-11
    • 2012-07-30
    • 2019-04-07
    • 1970-01-01
    • 2012-07-28
    • 2018-02-05
    • 2013-10-07
    • 2018-06-22
    相关资源
    最近更新 更多