禁止Apache顯示目錄索引,禁止Apache顯示目錄結構清單,禁止Apache浏覽目錄,這是網上提問比較多的,其實都是一個意思。
下面說下禁止禁止Apache顯示目錄索引的常見的3種方法。
要實作禁止Apache顯示目錄索引,隻需将 Option 中的 Indexes 去掉即可。
1.修改目錄配置
Options
indexes
FollowSymLinks,indexes的作用是,如果這個目錄下面沒有index檔案,那麼有indexes屬性,那麼就會把目前的目錄結構在浏覽器中列出來;如果沒有indexes,則不會列出目錄
<Directory "/var/www/html">
Options indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
網站目錄”/var/www/html”配置如下
測試結果如下
2.修改apache的httpd.conf屬性
搜尋“Options Indexes FollowSymLinks”,修改為“Options FollowSymLinks”即可。
在Options Indexes FollowSymLinks在Indexes前面加上 – 符号。備注:在Indexes前,加 + 代表允許目錄浏覽;加 – 代表禁止目錄浏覽。這樣的話就屬于整個Apache禁止目錄浏覽了。
經過測試在apache2.2.15版本中,使用’+-‘并不适用,而是需要把indexes添加或者删除才可以
如果是配置虛拟機,則如下:
<VirtualHost *>
<Directory "../vhosts/xx.xxx.com">
Options indexes FollowSymLinks # 修改為 -Indexes 即可
</Directory>
ServerAdmin [email protected].com
DocumentRoot "../vhosts/xx.xxx.com"
ServerName xx.xxx.com:
ServerAlias xx.xxx.com
ErrorLog logs/xx.xxx.com-error_log
</VirtualHost>
3.通過.htaccess檔案來實作
可以在根目錄建立或修改 .htaccess 檔案中添加
<Files *>
Options -Indexes
</Files>