Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
加载index.php作为我在php中的第一页_Php_Apache - Fatal编程技术网

加载index.php作为我在php中的第一页

加载index.php作为我在php中的第一页,php,apache,Php,Apache,如何在我的php项目中让index.php成为项目加载的第一页而不是index.html您可以通过htaccess 在htaccess文件中编写以下代码 DirectoryIndex index.php 在apache.conf中搜索DirectoryIndex,并确保index.php位于index.html之前。像这样: DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm 如果您没有访问

如何在我的php项目中让index.php成为项目加载的第一页而不是index.html

您可以通过
htaccess

htaccess
文件中编写以下代码

DirectoryIndex index.php

在apache.conf中搜索
DirectoryIndex
,并确保index.php位于index.html之前。像这样:

DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm

如果您没有访问apche配置的权限,或者不想全局设置这一行,您也可以将这一行添加到.htaccess文件中,因此有一个很好的解释,要执行OP要求的操作,您必须在Apache中使用
DirectoryIndex
。在站点配置或.htaccess中,必须放置以下内容:

DirectoryIndex index.php
这就告诉apache将
index.php
作为主文件启动。因此,加载
domain.tld/
确实会加载
index.php

DirectoryIndex index.php index.html
这将加载
index.php
,但如果不存在,它将尝试加载
index.html
。列出的文件顺序是apache首先查找的


更多详细信息

您可能真正想要的是针对Apache的解决方案,而不是PHP。除非你正在使用IIS或其他东西?获得帮助的最佳方式是能够回答?还有,你做了什么研究?研究感谢.htaccess提示!:)@hek2mgl欢迎您:)