Apache显示/更改除index.html之外的默认页面

时间:2020-01-09 10:37:08  来源:igfitidea点击:

如何在Apache Web服务器下显示或更改除index.html或index.php以外的默认页面?
您需要在Apache下使用DirectoryIndex指令设置除index.html或index.php之外的默认页面。

当客户端通过在目录名末尾指定/来请求目录的索引时,DirectoryIndex指令设置要查找的资源或文件的列表。

编辑httpd.conf

打开您的Apache配置文件httpd.conf

# vi httpd.conf

找出如下所示的行:

DirectoryIndex

现在根据您的要求进行设置:

DirectoryIndex index.html index.htm default.htm index.php index.pl

保存并关闭文件。
重新启动Apache Web服务器:

# /etc/init.d/httpd restart

请注意,如果您无权访问Apache配置文件。
将DirectoryIndex添加到您的.htaccess文件。

您还可以指定php或pl动态脚本。
另请注意,文档不需要相对于目录。
考虑以下示例

DirectoryIndex index.html index.pl /nav/index.php

如果目录中不存在index.html或index.pl,则上述将导致执行php脚本/nav/index.php。