php - 条件目录索引

标签 php .htaccess content-management-system directoryindex

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

  • 使用 index.php 作为默认目录索引
  • 如果出现 404 错误,则将 DirectoryIndex 设置为 index2.php

有谁知道这是否/如何可能?

最佳答案

(404 = 未找到文件),所以您实际上是在寻找一种允许遍历可能的索引文件列表的方法)
将以下行添加到您的 .htaccess 文件中:

DirectoryIndex index.php index2.php

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

另请参阅:Apache Docs > DirectoryIndex directive .

关于php - 条件目录索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7697379/

相关文章:

php - 如何将 php session 绑定(bind)到用户 SSL 证书

php - 将代码(方法)注入(inject)类?

wordpress - 带有域掩码的 htaccess 重定向 Wordpress 站点不起作用

php - 如何将自托管的 wordpress 和 live 站点的已安装插件升级到最新可用版本而不会遇到任何问题?

html - 背景 CSS DIV 背景不在移动设备上拉伸(stretch)

asp.net - 一个 IIS 服务器中的 JavaScript 问题,但不是另一个

php - Facebook 图形 API。如何获取帖子的评论

php - 需要将命令行 (Linux) CURL 转换为具有请求数据负载 ("-d "的 PHP CURL)

php - .htaccess 打开 .css 而不是 .php

php - 资源解释为样式表,但使用 MIME 类型文本/html 和 PHP 中生成的 css 传输