通过重定向防止目录列表? [英] Preventing directory listing by redirecting?

查看:27
本文介绍了通过重定向防止目录列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 .htaccess 来防止目录列表.
我在 /location/ 中有页面,但我没有索引文件.所以我想重定向到 /location/about.php 例如.

I want to use .htaccess to prevent directory listing.
I've got pages within /location/ but I don't have an index file. So I want to redirect to /location/about.php for example.

有没有办法做到这一点,而无需创建 index.html 并将请求重定向到那个?

Is there a way to do this, without creating an index.html and redirecting requests to that?

感谢您的帮助!

推荐答案

如果您需要一个文件来代替 'index.html',请参阅DirectoryIndex" 告诉它用什么文件代替'index.html':

If you're asking for a file in place of 'index.html', see "DirectoryIndex" to tell it what files to use in place of 'index.html':

DirectoryIndex about.php index.html
Options –Indexes

...如果您试图将所有目录重定向到一个页面,那么我会作弊并执行以下操作,这将主要满足您的要求:

... if you're trying to redirect all directories to a single page, then I'd cheat and do the following, which will mostly do what you're asking for:

Options +Indexes
IndexOptions +SuppressHTMLPreamble
IndexIgnore *
HeaderName /includes/header.html
ReadmeName /includes/readme.html

... 并将/includes/header.html 设置为您想要的任何消息(或包含元重定向),并将/includes/readme.html 设置为空白.

... and set /includes/header.html with whatever message you want (or containing a meta-redirect), and /includes/readme.html to be blank.

这篇关于通过重定向防止目录列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆