When to Use Index.PHP Instead of Index.Html

How to make Apache serve index.php instead of index.html?

As others have noted, most likely you don't have .html set up to handle php code.

Having said that, if all you're doing is using index.html to include index.php, your question should probably be 'how do I use index.php as index document?

In which case, for Apache (httpd.conf), search for DirectoryIndex and replace the line with this (will only work if you have dir_module enabled, but that's default on most installs):

DirectoryIndex index.php

If you use other directory indexes, list them in order of preference i.e.

DirectoryIndex index.php index.phtml index.html index.htm

when to use index.php instead of index.html

You will have to choose the PHP extension (.php) when you want php code to be executed in the file. PHP code is code between the opening <?php or <? and the closing ?> tags.

When no PHP code should be executed you can use the .html extension.

Usually when using the .php extension you are telling the web server, that it should use a php interpreter to process the file before it will be delivered to the browser. The php interpreter will then replace all content between the <?php and ?> by the output of the PHP code. Just as if you wrote it manually. The processed file will then be delivered to the browser.

However, using the .php extension to tell the web server to process php code is configurable. If you want you can use other file extensions too.

There is another thing that should be pointed out. When you only type the url path (without a filename) like :

http://www.myserver.com/

there is an order of extensions (filenames) which the webserver (apache) searches for an index document. For example an apache config may contain a section like:

<IfModule mod_dir.c>
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>

Meaning that the index document is searched in the order above. This means if you place an index.html and a index.php in the same folder - and having the configuration above - always the index.html would be delivered by the server.

Is it bad practice to use index.php instead of index.html?

No issue with using index.php instead of index.html. It does not affect search engine rankings - So the only reason you would want to change it is for aesthetics.

If you want to use index.html instead of index.php, there are two options:

Firstly, you can rewrite extensions using .htaccess. Add the following lines to your .htaccess, and they will remap all requests for a .html page to a .php one without the URL changing.

RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php [nc]

Secondly, you can allow .html files to be parsed by the PHP interpreter. To do this, add one of the following lines to your .htaccess (Different hosts have different syntax, the first works for most shared hosts)

AddHandler application/x-httpd-php5 .html .htm

AddType application/x-httpd-php .html .htm

AddHandler application/x-httpd-php .html .htm

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.

Index.php instead Index.html, how to access, and where is the .htaccess file that i have apparently have to change?

The thing is that you are trying to view a WordPress theme, without the installation of WordPress.

You need first to download and install WordPress on your hosting and then upload this theme via WordPress admin (very easy). Good luck with that and enjoy WordPress



Related Topics



Leave a reply



Submit