Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess DirectoryIndex does not work

I have two index files in my public_html folder (Apache), index.html and index.php

By default Apache seems to be directing traffic to index.php, so I want to change that to index.html. I added a .htaccess file in the same directory with this in it:

DirectoryIndex index.html

But when visitors go to the website (www.example.com/), they are still directed to index.php

Why is this?

like image 263
Zeno Avatar asked Apr 18 '12 15:04

Zeno


People also ask

What is DirectoryIndex in Apache?

The DirectoryIndex directive sets the list of resources to look for, when the client requests an index of the directory by specifying a / at the end of the directory name. Local-url is the (%-encoded) URL of a document on the server relative to the requested directory; it is usually the name of a file in the directory.

How do I change the directory index?

If you want the directory index page setting to apply to your entire web site, add the DirectoryIndex directive to the . htaccess file in the public_html directory. All subdirectories beneath it that do not have their own . htaccess file will inherit the setting.


1 Answers

For those who are still searching for the answer - just like the OP suggests, add the following line to your .htaccess file:

DirectoryIndex index.php

Make sure your hosting is allowing htaccess override in httpd.conf

AllowOverride All

If it's not enabled, you'll have to contact your hosting provider.

like image 195
bdereta Avatar answered Oct 29 '22 17:10

bdereta