首页 > 解决方案 > Apache HTAccess 未将 HeaderName 和 FooterName 应用于索引

问题描述

我目前正在尝试为将使用它的文件夹建立索引。我遇到的问题是HeaderNameand te FooterName它们只是不适用于索引。header.html文件包含以下内容:

<html>
    <head>
        <title>My Stuff</title>
        <style type="text/css">
        body {
            background: #eee;
            margin: 33px;
            color: #333;
        }
        </style>
    </head>

.htaccess文件具有以下内容:

# enable indexes
Options +Indexes

# htaccess protection
<Files ~ "^.*\.([Hh][Tt][Aa])">
 order allow,deny
 deny from all
</Files>

# directory customization
<IfModule mod_autoindex.c>
 # index options
 IndexOptions IgnoreCase
 IndexOptions FancyIndexing
 IndexOptions FoldersFirst
 IndexOptions NameWidth=*
 IndexOptions DescriptionWidth=*
 IndexOptions SuppressHTMLPreamble
 
 # display order
 IndexOrderDefault Descending Name
 
 # page customization
 HeaderName header.html
 ReadmeName footer.html
 
 # ignore page customization files and others
 IndexIgnore header.html footer.html favicon.ico .htaccess .ftpquota .DS_Storeicons *.log *,v *,t .??* *~ *# errorlog
</IfModule>

我怎样才能解决这个问题?我只是无法让它工作并清除了我的缓存(多次),我也在其他浏览器上尝试过。我一直在关注如何设置它的教程(因为我不熟悉.htaccess文件和相关的东西)

我从索引中获得的 HTML 源代码与默认值相同,因此我无法判断它是否在做任何事情。我也可以说所有的东西都在游戏文件夹中,因此更加混乱。

我不确定我正在使用的主机/面板运行的是什么 Apache 版本,但不显示它。我环顾四周,找不到它。它很可能是最常用的一个,因为我在它上面所做的大多数事情都没有错误。我也没有收到任何错误.htaccess

标签: apache.htaccessindexing

解决方案


我只是在调查 IndexOptions 时发现了这一点,并决定进行测试。

它似乎对我有用(Chrome,在 hostpapa.com 上使用 LAMP 服务器)

演示:http ://www.wsurvey.org/stackOverflow/testIndexOptions/

您可以查看页面源以验证 SuppressHTMLPreamble 是否有效

.htaccess :

# test of indexOptions 
Options +Indexes

<IfModule mod_autoindex.c>
 # index options
 IndexOptions IgnoreCase
 IndexOptions FancyIndexing
  IndexOptions FoldersFirst
 IndexOptions NameWidth=*
 IndexOptions DescriptionWidth=*
  IndexOptions SuppressHTMLPreamble 
 
 # display order
 IndexOrderDefault Descending Name
 
 # page customization
  HeaderName header.html
  ReadmeName  readme.txt
 
 # ignore page customization files and others
 IndexIgnore header.html footer.html favicon.ico .htaccess .ftpquota .DS_Storeicons *.log *,v *,t .??* *~ *# errorlog
</IfModule>

并且 header.html 是(丑陋,但表明它有效)

<html>
    <head>
        <title>This is a   title</title></title>
        <style type="text/css">
        body,.foo {
            background: tan;
            margin: 33px;
            color: blue;
        }
        .foo {
             background:cyan;
        }
        </style>
    </head>
    
    <body>
    <div class="foo" >This is content in header.html !</div>

推荐阅读