如何让下载的PHP文件,但拒绝目录列表直接访问 [英] How to allow downloading files with PHP, but deny direct access to directory listings
问题描述
我在我的服务器上使用Apache,我想我的允许访问者下载免费的资源。然而,preserve带宽,甚至一点点,我想拒绝对资源的这样的根文件夹直接访问:
I am using Apache on my server and I'd like to allow my visitors to download resources free of charge. However, to preserve even a little bit of bandwidth I'd like to deny direct access to the root folder of the resources like this:
www.myhost.com/resources/file.wav
如果访问者删除 file.wav
从URL中,他们能获得的所有声音一下子,因此我不得不人们只是下载像疯了似的。我不希望这样。
If the visitor removes file.wav
from the URL, they have access to all sounds at once and thus I'd have people just downloading like crazy. I don't want that.
我如何阻止进入该根目录的用户,所有子文件夹?
How can I stop the users from going into that root directory, and any subfolders?
推荐答案
要做到这一点,甚至没有与的.htaccess
(虽然这是一个很好搞乱死者最简单的方法想法)是简单地把一个index.html文件的文件夹中,并设置其权限为700。
The dead easiest way to do this, without even messing with .htaccess
(though that is a good idea) is to simply put an index.html file in the folder and set its permissions to 700.
如果您只想关闭目录列表,你可以创建一个这样的htaccess文件:
If you want to just turn off directory listings you can create an htaccess file with this:
<Directory /path/to/directory>
Options -Indexes
</Directory>
如果你想拒绝访问子目录,你可以用这样的:
If you want to deny access to sub-directories, you can use this:
<Files subdirectory/*>
deny from all
</Files>
如果你想允许访问只是.wav文件,你可以这样做:
If you want to allow access to just the .wav files, you can do this:
<Files *.wav>
allow from all
</Files>
这篇关于如何让下载的PHP文件,但拒绝目录列表直接访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!