温馨提示×

更改Apache默认起始(索引)页面:DirectoryIndex

小云
180
2023-09-12 07:54:30
栏目: 编程语言

要更改Apache的默认起始页面(索引页面),您需要编辑Apache的配置文件。根据您使用的操作系统和安装方式的不同,配置文件的位置可能会有所不同。以下是一般可用的位置:

  • Ubuntu/Debian:/etc/apache2/apache2.conf/etc/apache2/sites-enabled/000-default.conf

  • CentOS/RHEL:/etc/httpd/conf/httpd.conf/etc/httpd/conf.d/welcome.conf

  • macOS:/etc/apache2/httpd.conf

打开配置文件后,找到 DirectoryIndex 指令。该指令定义了Apache按顺序查找的文件名称列表,以确定默认的索引页面。默认情况下,它通常设置为:

DirectoryIndex index.html index.php

您可以根据您的需求更改这个列表。例如,如果您想将 index.html 放在第一位,则可以将指令更改为:

DirectoryIndex index.html index.php index.htm

保存配置文件后,重新启动Apache服务器以使更改生效。根据您的操作系统和安装方式,可以使用以下命令重启Apache:

  • Ubuntu/Debian:sudo service apache2 restart

  • CentOS/RHEL:sudo systemctl restart httpd

  • macOS:sudo apachectl restart

现在,当访问Apache服务器时,它将首先查找 index.html,然后是 index.php,最后是 index.htm。如果找到其中任何一个文件,则将其作为默认的索引页面。

0