douyiken0968 2012-03-30 14:27
浏览 40
已采纳

将mod_autoindex替换为所有目录中的PHP索引器,而不向所有目录添加index.php

I like the ability to automatically index a folder, so that I can serve a large number of files, without adding links to a page all the time. However I dislike the httpAuth login box that comes with using .htaccess to secure a directory. Plus there are more features I wanted on my indexes. So I have written a PHP script to generate indexes the way I want, so that I can control everything with PHP, store users in SQL, add extra links to my file editor, and log in with a nice looking web form.

The problem is any new directory needs an index.php file that includes the script, or I just get apache indexes. Which means copying a one line index.php file to every directory. I could generate it using PHP, but if I am working with FTP to manage files that will not solve all the problems. Is there any way to configure apache to display my index script in any directory that does not have an index files of its own? Such that it acts just like mod_autoindex? But with my custom script.

  • 写回答

1条回答 默认 最新

  • dongyuedaochen8415 2012-03-30 14:34
    关注

    Put the index.php in your root, then use redirect

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} -d #if directory exists
    RewriteRule . /index.php [L]
    

    Then inside index.php use $_SERVER['REQUEST_URI'] to figure out which folder was requested, then use PHP to display what you wanna display, e.g. using opendir, readdir, etc (don't forget to handle the '.' and '..' unix files)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退