【发布时间】:2009-08-04 18:29:03
【问题描述】:
我想使用.htaccess 来阻止目录列表。
我在 /location/ 中有页面,但我没有索引文件。所以我想重定向到 /location/about.php 例如。
有没有办法做到这一点,而无需创建 index.html 并将请求重定向到那个?
感谢您的帮助!
【问题讨论】:
我想使用.htaccess 来阻止目录列表。
我在 /location/ 中有页面,但我没有索引文件。所以我想重定向到 /location/about.php 例如。
有没有办法做到这一点,而无需创建 index.html 并将请求重定向到那个?
感谢您的帮助!
【问题讨论】:
如果您要求使用文件代替“index.html”,请参阅“DirectoryIndex”以告诉它要使用哪些文件代替“index.html”:
DirectoryIndex about.php index.html
Options –Indexes
...如果您尝试将所有目录重定向到单个页面,那么我会作弊并执行以下操作,这主要会满足您的要求:
Options +Indexes
IndexOptions +SuppressHTMLPreamble
IndexIgnore *
HeaderName /includes/header.html
ReadmeName /includes/readme.html
...并将 /includes/header.html 设置为您想要的任何消息(或包含元重定向),并将 /includes/readme.html 设置为空白。
【讨论】:
我知道这是一个较旧的线程,但我只需要实现类似的东西并按照以下方式进行:
Options -Indexes
ErrorDocument 403 /location/about.php
基本上,Options -Indexes 会阻止目录列表,ErrorDocument 403 会重写默认的 403 消息。
【讨论】:
更改 DirectoryIndex 和 Options 有效,但使用 mod_alias 意味着您不必在嵌套目录中将其更改回。
Redirect 303 /location/ /location/about.php
【讨论】:
这里是您需要的直接链接:
http://www.webweaver.nu/html-tips/web-redirection.shtml
如果您需要更高级的东西来处理参数或需要将旧 URL 重新映射到新 URL,您可以使用 URL 重写:
http://corz.org/serv/tricks/htaccess2.php
阻止目录列表(或返回空目录列表):
http://www.besthostratings.com/articles/prevent-directory-listing.html
【讨论】: