您好,我正在做一个项目,我在根目录下有两个索引文件,一个是 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>
但是它们都不起作用,它总是使 index.php 成为默认值,但是当它不可用时它不会加载 index.html。
如果我先编写 index.html,然后编写 index.php,那么它会加载 index.html,但如果 index.html 不可用,则不会加载 index.php。
简而言之,我们可以说首选项不起作用。
最佳答案
您可以指定多个文件名,Web 服务器将搜索每个文件,直到找到匹配项。考虑这个示例指令:
将此写入根目录下的 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>
来源:
关于php - 无法在 apache2 [Debian 7.1] 中设置默认索引页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34216965/