Apache不会自动在root中执行index.php的脚本

时间:2013-03-25 23:01:08

标签: php apache http

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

但是如果我在index.php中添加一些php脚本,它会加载index.html.en(It Works!)。但是,如果我键入http://gustavopi-macmini.local/index.php,它会加载并执行脚本。

另外,如果我将index.php文件放在子目录中并输入http://gustavopi-macmini.local/somesubdirectory/,它会正常加载并执行index.php ...

为什么会出现从根目录中的php脚本“跳”出来的奇怪行为?

2 个答案:

答案 0 :(得分:10)

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

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

要更改此设置,请更改“目录索引”文件的顺序;

DirectoryIndex index.php index.html

阅读此处的文档:

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

答案 1 :(得分:0)

不要在 index.html index.php 之间添加逗号(,),因为" thaJeztah"指令 DirectoryIndex 中的顺序很重要,它定义了在请求的目录中有两个文件index.html和index.php时将提供的文件:

如果您想优先考虑index.html,请写下:

DirectoryIndex index.html index.php

如果你想优先考虑index.php,请写下:

DirectoryIndex index.php index.html