11 Vote

Multiple Index Files: Force Server to load index.php instead of index.html

Question by Guest | Last update on 2024-01-15 | Created on 2012-08-24

I have the following unusual problem: In my webspace directory is both an index.php and an index.html. For some reason, however, always the index.html is loaded first. But I would like that the index.php is loaded first instead.

Is there a way or is not changeable?

ReplyPositiveNegativeDateVotes
11 Vote

Why do you have an index.html and an index.php in the directory? That does not really make much sense, does it?

I would leave only one of these index files in the directory and give the rest of the files different names or you can only link them from another folder. Then you have not the problem.
Last update on 2024-01-15 | Created on 2012-08-27

ReplyPositive Negative
3Best Answer3 Votes

You can customize your htaccess file to determine an access order to the index files.

Just add the following line into your htaccess:

DirectoryIndex index.php index.html

This will force the server to first look for the file index.php and then subsequently for the file index.html (if no index.php exists). If both files are not present, there will be an Access Forbidden Error (403) or the directory with all the files will be displayed.

By the way, you can also specify files after DirectoryIndex that are not named "index" at all. For example:

DirectoryIndex abc.html def.php index.php

With this, first the abc.html is displayed, if available. And after that, def.php or index.php - depending on which of these files are available.
Last update on 2024-01-15 | Created on 2012-08-26

ReplyPositive Negative
Reply

Related Topics

HTACCESS: Simplify URL

Tutorial | 0 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.