拒绝访问除索引文件之外的所有文件 - Apache2

发布于 2024-12-11 13:39:10 字数 371 浏览 0 评论 0原文

我正在配置 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>

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

I'm configuring an Apache2 server, but I'm having trouble figuring out how to deny access to all files/directories except the index file.

My website resides inside /var/www/

This is my current setup in the /etc/apache2/apache2.conf file:

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

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

How do I solve my problem? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

荒岛晴空 2024-12-18 13:39:11

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

这可以通过 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]

I think you're better off simply piping everything to the index file, not denying access to everything else.

This can be done through 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]
叫思念不要吵 2024-12-18 13:39:10

尝试为index.php 添加。如果它在此位置不起作用,请将其移至目录的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>

Try adding a <FilesMatch> for index.php. If it doesn't work in this position, move it above the directory's Deny from all. Change index.html to whatever your index file is.

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文