2

This is strange: my Apache is configured with DirectoryIndex index.html,index.php so when I type http://gustavopi-macmini.local/ it searches for index.php and loads it ok if there is only html tags in the file.

But if I put some php script in index.php, it loads index.html.en instead (It Works!). However, if I type http://gustavopi-macmini.local/index.php it loads and executes the script.

Also, if I put an index.php file in a subdirectory and type http://gustavopi-macmini.local/somesubdirectory/ it loads and executes index.php normally as it should...

Why this strange behavior of "jumping" from a php script in the root occurring?

4

2 回答 2

10

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

在您的情况下,如果 anindex.html和 aindex.php都存在,Apache 将选择index.html.

要改变这一点,改变“目录索引”文件的顺序;

DirectoryIndex index.php index.html

在此处阅读文档:

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

于 2013-03-25T23:05:11.693 回答
0

不要将逗号 (,) 放在index.htmlindex.php之间,正如“thaJeztah”所说,DirectoryIndex指令中的顺序很重要,它定义了如果有两个文件索引将提供的文件。请求目录中的 html 和 index.php :

如果你想优先考虑 index.html 写这个:

DirectoryIndex index.html index.php

如果你想优先考虑 index.php 写这个:

DirectoryIndex index.php index.html

于 2014-10-19T00:43:44.563 回答