【问题标题】:Deny access to all files except index file - Apache2拒绝访问除索引文件之外的所有文件 - Apache2
【发布时间】:2011-12-15 01:02:26
【问题描述】:

我正在配置一个 Apache2 服务器,但我无法弄清楚如何拒绝对除索引文件之外的所有文件/目录的访问。

我的网站位于 /var/www/ 中

这是我当前在 /etc/apache2/apache2.conf 文件中的设置:

<Directory />
  Order Deny,Allow
  Deny from all
  Options None
  AllowOverride None
</Directory>

<Directory /var/www/>
  Order Allow,Deny
  Allow from all
</Directory>

如何解决我的问题?谢谢!

【问题讨论】:

  • SO 题外话;属于 webmasters.stackexchange.com

标签: linux apache


【解决方案1】:

尝试为 index.php 添加&lt;FilesMatch&gt;。如果在此位置不起作用,请将其移至目录的Deny from all 上方。将index.html 更改为您的索引文件。

<Directory />
  Order Deny,Allow
  Deny from all
  Options None
  AllowOverride None
</Directory>

<Directory /var/www/>
  # Deny first, then allow
  Order deny,allow
  # Deny everyone from everything
  Deny from all

  <FilesMatch index\.html>
    # but allow index.html
    Allow from all
  </FilesMatch>
</Directory>

【讨论】:

    【解决方案2】:

    我认为您最好将所有内容都通过管道传输到索引文件,而不是拒绝访问其他所有内容。

    这可以通过 RewriteRule 来完成:

    RewriteEngine On
    # index goes to index (this is first to prevent infinite loop)
    RewriteRule ^/index\.html$ - [L]
    # everything else goes to index
    RewriteRule .* /index.html [L]
    

    【讨论】:

      猜你喜欢
      • 2015-09-13
      • 2011-03-25
      • 2012-10-26
      • 2010-11-23
      • 1970-01-01
      • 2013-07-25
      • 2020-01-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多