如何在PHP中获取Apache的DirectoryIndex?

时间:2011-07-01 20:34:42

标签: php apache directoryindex

有没有办法在Apache下运行PHP中的DirectoryIndex数组(或类似的东西)?例如,我希望能够检查特定目录中是否存在其中一个DirectoryIndex文件。这与How can I get the DirectoryIndex filename for a given URI using PHP?有关,但它并没有提出同样的问题,所以尽管它有相似之处,请不要指出它。

编辑:我不想去文件解析。

2 个答案:

答案 0 :(得分:4)

不幸的是,因为Apache没有通过environment variables提供它。

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

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

答案 1 :(得分:0)

您可以通过以下方式获取/** * Add scroll-to-div class to main navigation <a> links. */ function add_menuclass($ulclass) { return preg_replace('/<a /', '<a class="scroll-to-div"', $ulclass); } add_filter('wp_nav_menu', 'add_menuclass'); /** * Bootstrap modal trigger from a WordPress Menu item, the modal trigger requires an attribute of data-div * with a value of what page the code corresponds with. // About link. */ add_filter( 'nav_menu_link_attributes', 'about_menu_attribute_add', 10, 3 ); function about_menu_attribute_add( $atts, $item, $args ) { // Set the menu ID $menu_link = 3622; // Conditionally match the ID and add the attribute and value if ($item->ID == $menu_link) { $atts['data-div'] = 'about'; } //Return the new attribute return $atts; };

DirectoryIndex

此方法仅在运行Apache DSO模块时有效。

相关问题