Apache不会自动执行索引脚本.php在根目录中



这很奇怪:我的Apache配置了DirectoryIndex index.html,index.php,所以当我输入http://gustavopi-macmini.local/时,它会搜索index.php并加载它,如果文件中只有html标签。

但如果我把一些php脚本在index.php,它加载index.html.en而不是(它的工作!)。但是,如果我输入http://gustavopi-macmini.local/index.php,它将加载并执行脚本。

此外,如果我将index.php文件放在子目录中并键入http://gustavopi-macmini.local/somesubdirectory/,它会正常加载并执行index.php,因为它应该…

为什么这个奇怪的行为"跳"从php脚本在根发生?

定义的'目录索引'文件的顺序也决定了它们的优先级。

在您的情况下,如果同时存在index.htmlindex.php, Apache将选择index.html

修改目录索引文件的顺序;

DirectoryIndex index.php index.html

阅读这里的文档:

http://httpd.apache.org/docs/2.2/mod/mod_dir.html

不要在index.htmlindex.php之间放逗号(,),正如"thaJeztah"所说的,指令DirectoryIndex中的顺序是重要的,它定义了如果在请求目录中有两个文件index.html和index.php将被服务的文件:

如果你想给index.html优先级,可以这样写:

DirectoryIndex index.html index.php

如果你想给index.php优先级,写:

DirectoryIndex index.php index.html

最新更新