Why Does Index.HTML Have Priority Over Index.Php

Why does index.html have priority over index.php?

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.

Giving index.html priority over index.php

It depends on your server configuration for now, some .htaccess file you may not have access too. You can define/overrule this in your own htaccess using, for example :

DirectoryIndex index.html index.php

the priority depends on the order you set the filenames in that line

Server page priorities between index.php or index.html

If you use Apache (which I assume you do since you tagged this with htaccess) you can change your Apache config/htaccess's DirectoryIndex property to include the order of priority of index files:

DirectoryIndex index.html index.htm index.php index.php4 index.php5

Here's the "algorithm":

  • Does index.html exist in the current folder? If yes, then load it, if no, continue:
  • Does index.htm exist in the current folder? If yes, then load it, if no, continue:
  • Does index.php exist in the current folder? If yes, then load it, if no, continue:
  • Does index.php4 exist in the current folder? If yes, then load it, if no, continue:
  • Does index.php5 exist in the current folder? If yes, then load it, if no, continue:
  • Send a 404 page not found error

Which means you can create an index.html file and then delete it once you want your site to run normally. Keep in mind that anyone can still access index.php if they wish - they just need to specify it.

How do i make 'index.php' higher priority than 'index.html' with a Shell script

All you're doing is making index.php higher priority than index.html. It's an odd thing to need to do, and probably better done in .htaccess or something. However, if you really want to make the change in the config file directly you can use sed. In this case something like the following:

cd /etc/apache2/mods-enabled
sed -e 's/\s*DirectoryIndex.*$/\tDirectoryIndex index\.php <...> index\.htm/' \
dir.conf > dir.conf.tmp && mv dir.conf.tmp dir.conf

You need to be sure that 'DirectoryIndex' only appears once though, and fill in <...> with the rest of the line (escaping dots: 'index.pl' -> 'index\.pl').

priority to index.html for index.php in .htaccess

Try this code :

RewriteEngine On
RewriteRule ^$ /index.html [L,R=301]

Precedence, HTML and PHP Index File

Check the DirectoryIndex directive of Apache.

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

For instance

DirectoryIndex index.html index.php

Will try to serve first the html, if it doesn't exist it will serve the php.



Related Topics



Leave a reply



Submit