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

Unable to set default index page in apache2 [Debian 7.1]

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

DirectoryIndex index.php index.html

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

<Directory "/home/zhengyu/webroot/engine5g/rentown.com/">
          DirectoryIndex index.php index.html default.htm
</Directory>

我也试过另一种方法:

<Directory "/home/zhengyu/webroot/engine5g/rentown.com/">
          DirectoryIndex index.php index.html
          Options Indexes FollowSymLinks MultiViews
          AllowOverride None
          DirectoryIndex index.php index.html
          Order allow,deny
          allow from all
</Directory>

但是其中 none 有效,它总是使 index.php 默认,但是当它不可用时它不会加载 index.html。

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

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

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

将此写入根目录下的 htaccess 文件中:

DirectoryIndex index.php index.html

In this directive, when a visitor requests the directory name, the web server looks first for an index.php file. If it does not find an index.php file, it looks for an index.html file, and so on until it finds a match or runs out of files to search.

或者这样试试

# 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>

来源: