条件目录索引

时间:2011-10-08 14:16:05

标签: php .htaccess content-management-system directoryindex

我在同一目录中安装了两个CMS。其中一个CMS允许将index.php文件重命名为index2.php,另一个不允许。理想情况下,我想在.htaccess文件中设置一个条件规则:

  • 使用index.php作为默认的DirectoryIndex
  • 如果出现404错误,请将DirectoryIndex设置为index2.php

有谁知道这是否可行?

1 个答案:

答案 0 :(得分:2)

(404 =未找到文件),因此您实际上正在寻找允许浏览可能索引文件列表的方法
将以下行添加到.htaccess文件中:

DirectoryIndex index.php index2.php

index.php存在时,它会被使用。否则,使用index2.phpindex.phpindex2.php存在时,会使用index.php,因为它首先出现。

另请参阅:Apache Docs > DirectoryIndex directive

相关问题