Conditional DirectoryIndex

228 Views Asked by At

I have installed two CMSs in the same directory. One of the CMSs allows the index.php file to be renamed to index2.php, the other one does not. Ideally I'd like to set up a conditional rule in the .htaccess file which:

  • Uses index.php as the default DirectoryIndex
  • If there is a 404 error then set the DirectoryIndex to index2.php

Does anyone know if/how this possible?

1

There are 1 best solutions below

4
On

(404 = File Not Found), so you're actually looking for a method which allows going through a list of possible index files)
Add the following line to your .htaccess file:

DirectoryIndex index.php index2.php

When index.php exists, it's used. Otherwise, index2.php is used.
When index.php and index2.php exist, index.php is used, because it appeared first.

See also: Apache Docs > DirectoryIndex directive.