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?

2 Answers 2

10

The order of the defined 'directory index' files also determine their priority.

In your situation, if both an index.html and a index.php are present, Apache will pick the index.html.

To change this, change the order of the 'directory index' files;

DirectoryIndex index.php index.html

Read the documentation here:

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

Sign up to request clarification or add additional context in comments.

4 Comments

It doesn't affect the problem, Apache loads the php IF there is not php code inside. I tried anyway, but didn't work.
Apache loading index.html.en is caused by the 'Content Negotiation' module documentation if you don't need that, you can disable it.
This module can't be disabled, Apache stop working. However, this morning (after a good coffee) I saw a "," in DirectoryIndex between index.php index.html. Removing it solve the problem. I think this directive were ignore by syntax error so Content Negotiation handle looking for index.html or index.html.en causing the strange situation.
I had seen the comma and didn't include that in my example, but now see that I forgot to mention that.. sorry! However, glad that you were able to solve the problem!
0

Don't put comma (,) between index.html and index.php and as it is said by "thaJeztah" the order in the directive DirectoryIndex is important and it defines the file that will be served if there is the two files index.html and index.php in the requested directory:

If you want to give priority to index.html write this:

DirectoryIndex index.html index.php

If you want to give priority to index.php write this:

DirectoryIndex index.php index.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.