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

标签 php html apache .htaccess directoryindex

您好,我正在做一个项目,我在根目录下有两个索引文件,一个是 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/

相关文章:

java - 如何在android中获取web服务的所有权限?

php - `$/i` 在正则表达式中的含义

html - 文本垂直居中的两列

html - svg 元素的绝对定位不起作用

特定端口的 Apache 配置设置(PCI 合规性)

java - Apache POI poi-ooxml :4. 0.0 抛出 org.apache.poi.ooxml.POIXMLException

php - 分解/分解文本字符串的最佳分隔符 - @、!、<>、# 或 |

php - 如何在 PHP 中生成随机单词?

javascript - 这个网站是如何实现响应式布局的

php - xampp 安装。在安装 xampp/apache 时。我遇到错误,显示以下几行