24

I have a website on a server. The homepage is example.com/index.php .

OK, I uploaded an index.html named file to the server (the root dir) and when I typed in my site's domain into the browser's URL bar, I was suprised, because the index.html page loaded.

(example.com->example.com/index.html) So not what I wanted.

My question: Why did that happen? Why does index.html have advantage over index.php?

Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
Akos
  • 1,997
  • 6
  • 27
  • 40
  • 4
    Because that's the way your server is set up. You can make certain files take priority over others. If you need help setting up your server, check out server fault instead. Post your configuration. Are you using apache, IIS? what? – Matt Oct 24 '11 at 09:36

5 Answers5

52

It really depends on the Server you're using. This is a matter of configuration. It's not that there's any advantage from using html vs php filetype.

You could say that the .html variation takes precedence due to the fact that it's the most basic web format.

If you're using Apache, just check the default .htaccess setup:

DirectoryIndex index.html index.shtml index.php index.htm default.html Default.htm default.html Default.html default.shtml Default.shtml page1.html index.pl index.cgi index.php3 index.phtml home.htm home.html home.shtml index.wml

You can edit that and make it fit your needs.

MarioRicalde
  • 9,131
  • 6
  • 40
  • 42
  • OK thanks for the answer... Is this related to the .htaccess file? – Akos Oct 24 '11 at 09:37
  • 1
    @kuroir i don't think he meant advantage like that, i think he meant it in a way that it has a certain priority. Your answer still works though. – Matt Oct 24 '11 at 09:39
  • 2
    Yes, you can define that from your `.htaccess` file. Look the updated answer. – MarioRicalde Oct 24 '11 at 09:39
  • 1
    @Matt I know, just making sure. Since some people still think that it has something to do with SEO ;) – MarioRicalde Oct 24 '11 at 09:41
  • @Akos: Yes, the `DirectoryIndex` directive can be changed in `.htaccess` files. – Alix Axel Oct 24 '11 at 09:42
  • If your using WHM (CPanel Ver 106), visit Home -> Service Configuration -> Apache Configuration -> DirectoryIndex Priority. You will see a list of which extensions are used first. Add/Remove and adjust the order of directory index filenames. – Tom aka Sparky Dec 08 '22 at 21:40
14

@kuroir is right, that depends on the web server configuration, in Apache it's the DirectoryIndex:

DirectoryIndex index.html index.php index.cgi

That will give priority to .html files over .php files, and priority to .php files over .cgi files.

Alix Axel
  • 151,645
  • 95
  • 393
  • 500
3

I know this is old and has been accepted but I want to add to this in case someone else has this problem.

I came here when looking for a solution to the same problem. Entering the Wordpress "index.php" into the URL got redirected to "index.html". It had nothing to do with the .htaccess. I finally found the solution in their forum. Wordpress modified the program a couple years ago to strip "index.php" from URLs. So then of course it goes to your default (usually index.html).

To make it behave as you expect, you need to revert the change here: changeset 9203. See Forum topic

Joe
  • 31
  • 1
0

Well it depends on your hosting provider well yes 90% hosting provider gives priority to index.html instead of index.php or any other extention.

0

The biggest issue, as with all types of development, is maintenance. If you decide to change technology then by exposing the file extension you are setting yourself up for a lot of work - not to mention the security aspects of broadcasting your choice. The best situation is to avoid exposing extensions by using url rewriting.

Robert
  • 8,406
  • 9
  • 38
  • 57