禁用 Apache 上的目錄索引?

禁用 Apache 上的目錄索引?

我想停用 Apache 上的目錄索引。

這是我的完整 .htaccess 檔案。但一旦我取消註釋,Options -Indexes伺服器就會崩潰。

我究竟做錯了什麼?

#Options –Indexes

<IfModule mod_expires.c>

# Turn on the Expires engine
  ExpiresActive On

# CSS and JavaScript
  ExpiresByType text/css                  "access plus 1 hour"
  ExpiresByType application/javascript    "access plus 1 hour"

# Media: images
  ExpiresByType image/gif                 "access plus 1 month"
  ExpiresByType image/png                 "access plus 1 month"
  ExpiresByType image/jpg                 "access plus 1 month"
  ExpiresByType image/jpeg                "access plus 1 month"

# Webfonts
  ExpiresByType application/x-font-ttf    "access plus 1 month"
  ExpiresByType font/opentype             "access plus 1 month"
  ExpiresByType application/x-font-woff   "access plus 1 month"
  ExpiresByType image/svg+xml             "access plus 1 month"
  ExpiresByType application/vnd.ms-fontobject "access plus 1 month"

  <IfModule mod_headers.c>
    Header append Cache-Control "public"
  </IfModule>

</IfModule>

答案1

可能您的 Apache 已配置httpd.confAllowOverride這樣的值,它不允許您調整 .htaccess 中的任何選項。

您有權利存取httpd.confApache 錯誤日誌嗎?

答案2

萬一其他人遇到同樣的問題,問題是我會複製並貼上在行中:

Options –Indexes

Apache 無法處理連字符的編碼!

相關內容