禁止 apache 列出目錄

說明禁止Apache顯示目錄索引的常見的3種方法。要Apache禁止顯示目錄索引,只需將Options中的Indexes去掉即可。

(1)修改目錄配置:

Options Indexes FollowSymLinks <== 修改為: Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all

Indexes 的作用就是當該目錄下沒有 index.html 檔案時,就顯示目錄結構,去掉 Indexes ,Apache 就不會顯示該目錄的列表了。

(2)修改Apache配置檔案[httpd.conf]

搜尋“Options Indexes FollowSymLinks”,修改為“Options FollowSymLinks”即可。

Options Indexes FollowSymLinks刪除Indexes,這樣的話就屬於整個Apache禁止目錄瀏覽了。

如果是配置虛擬機器,

Options FollowSymLinks <== 刪除Indexes 即可
ServerAdmin mail@example.cxm
DocumentRoot "../vhosts/example.cxm"
ServerName shopex:80
ServerAlias example.cxm
ErrorLog logs/example.cxm-error_log

(3)通過.htaccess檔案

可以在根目錄新建或修改 .htaccess 檔案中新增

Options FollowSymLinks

就可以禁止Apache顯示目錄索引。

Apache將Indexes拿掉,點選連結目錄就不會秀出目錄來,會改成403 forbidden的訊息頁面。

403 forbidden意味著該頁面禁止存取,也達到避免目錄被看光光的目的。

MultiViews這是可以讓Apache送出多國語言支援的頁面

FollowSymLinks是讓Apache能夠連到其它的目錄去執行,如果是Windows系統的使用者,將這個功能拿掉比較好。

                       https://injerry.pixnet.net/blog/post/29883268