簡體   English   中英

拒絕訪問除索引文件以外的所有文件-Apache2

[英]Deny access to all files except index file - Apache2

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

我該如何解決我的問題? 謝謝!

嘗試為index.php添加<FilesMatch> 如果它在該位置不起作用,請將其從目錄移到目錄的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>

我認為您最好將所有內容都管道傳輸到索引文件,而不要拒絕訪問其他所有內容。

這可以通過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]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM