【问题标题】:How can I get Apache's DirectoryIndex in PHP?如何在 PHP 中获取 Apache 的 DirectoryIndex?
【发布时间】:2011-09-27 00:49:20
【问题描述】:

有没有办法在 Apache 下运行 PHP 中的 DirectoryIndex 数组(或类似的东西)?例如,我希望能够检查某个 DirectoryIndex 文件是否存在于特定目录中。这与How can I get the DirectoryIndex filename for a given URI using PHP? 相关,但它的要求并不完全相同,因此尽管相似,但请不要指向它。

编辑:我宁愿不必进行文件解析。

【问题讨论】:

    标签: php apache directoryindex


    【解决方案1】:

    很遗憾,没有,因为 Apache 没有通过 environment variables 提供它。

    如果您可以控制配置,则可以使用setenv 指令和DirectoryIndex。然后在 PHP 中使用apache_getenv() 读取它。

    否则我认为您必须自己解析 Apache 配置文件。

    【讨论】:

    • 感谢您富有洞察力的回答。 :)
    【解决方案2】:

    您可以通过这种方式获取DirectoryIndex

    basename(apache_lookup_uri(realpath(urlencode('Path_directory_here')))->uri);
    

    此方法仅适用于运行 Apache DSO 模块。

    【讨论】:

      猜你喜欢
      • 2017-09-03
      • 2015-09-04
      • 2011-03-08
      • 2017-08-13
      • 2020-11-20
      • 2013-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多