无法在apache2中设置默认索引页面[Debian 7.1]

时间:2015-12-11 05:52:48

标签: php html apache .htaccess directoryindex

您好我正在开发一个项目,我在root上有两个索引文件,一个是index.php,另一个是index.html。我想要将默认页面设置为index.php,如果它不可用,那么它应该适用于index.html。 我在互联网上搜索了很多,并为此找到了以下解决方案。

SimpleXMLElement Object
(
    [case1] => SimpleXMLElement Object
        (
            [name] => SimpleXMLElement Object
                (
                )
        )
    [case2] => SimpleXMLElement Object
        (
            [name] => SimpleXMLElement Object
                (
                )
        )
    [case3] => SimpleXMLElement Object
        (
            [name] => ukits
        )
)
Array
(
    [case1] => Array
        (
            [name] => 
        )
    [case2] => Array
        (
            [name] => 
        )
    [case3] => Array
        (
            [name] => ukits
        )
)

我在我的网站上使用此代码:

CentOS 6.7
PHP 5.4.45
SimpleXML Revision $Id: 16070fc92ad6f69cebb2d52ad3f02794f833ce39 $
libxml2 Version 2.7.6

我也尝试过另一种方式:

DirectoryIndex index.php index.html

但它们都没有工作,它总是使index.php成为默认值,但是当它不可用时它不会加载index.html。

如果我先写index.html然后再写index.php然后加载index.html,但如果index.html不可用,则不会加载index.php。

简而言之,我们可以说首选项不起作用。

1 个答案:

答案 0 :(得分:1)

您可以指定多个文件名,并且Web服务器将搜索每个文件,直到找到匹配项为止。考虑这个示例指令:

将此内容写入root上的htaccess文件:

DirectoryIndex index.php index.html
  

在此指令中,当访问者请求目录名称时,Web   server首先查找index.php文件。如果没找到   index.php文件,它查找index.html文件,依此类推   找到匹配项或用完要搜索的文件。

或尝试这种方式

# Example A: Set index.html as an index page, then add index.php to that list as well.
<Directory "/foo">
    DirectoryIndex index.html
    DirectoryIndex index.php
</Directory>

# Example B: This is identical to example A, except it's done with a single directive.
<Directory "/foo">
    DirectoryIndex index.html index.php
</Directory>

# Example C: To replace the list, you must explicitly reset it first:
# In this example, only index.php will remain as an index resource.
<Directory "/foo">
    DirectoryIndex index.html
    DirectoryIndex disabled
    DirectoryIndex index.php
</Directory>

来源: