Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make index.html default, but allow index.php to be visited if typed in

Tags:

html

.htaccess

I have the following line in my .htaccess file:

DirectoryIndex index.html index.php 

Everytime I go to index.php it takes me to index.html. Is it possible to allow for both, but leave index.html the default for users visiting www.domain.com?

like image 714
Matt Rowles Avatar asked Apr 03 '12 22:04

Matt Rowles


People also ask

Is index html the default?

Default HomepageThe index. html page is the most common name used for the default page shown on a website if no other page is specified when a visitor requests the site.


2 Answers

By default, the DirectoryIndex is set to:

DirectoryIndex index.html index.htm default.htm index.php index.php3 index.phtml index.php5 index.shtml mwindex.phtml 

Apache will look for each of the above files, in order, and serve the first one it finds when a visitor requests just a directory. If the webserver finds no files in the current directory that match names in the DirectoryIndex directive, then a directory listing will be displayed to the browser, showing all files in the current directory.

The order should be DirectoryIndex index.html index.php // default is index.html

Reference: Here.

like image 78
The Alpha Avatar answered Sep 20 '22 09:09

The Alpha


If you're using WordPress, there is now a filter hook to resolve this:

remove_filter('template_redirect', 'redirect_canonical');  

(Put this in your theme's functions.php)

This tells WordPress to not redirect index.php back to the root page, but to sit where it is. That way, index.html can be assigned to be the default page in .htaccess and can work alongside index.php.

like image 43
Natacha Beaugeais Avatar answered Sep 22 '22 09:09

Natacha Beaugeais