如何阻止对url目录的访问 [英] How block access to url directory
问题描述
我具有以下链接:www.mysite.com/uploads/file.pdf
I have the follow link : www.mysite.com/uploads/file.pdf
我希望用户下载文件。但是我不希望他从该目录中Vizualize文件。我该怎么做?
I want the user to download the file. But I do not want him vizualize files from this directory. How can I do this?
我正在使用PHP和Apache。
I'm using PHP and Apache.
推荐答案
最好在.htaccess文件中使用 Options -Indexes
Even better use Options -Indexes
in your .htaccess file
创建一个名为<$ c的文件$ c> .htaccess 在该目录上,并添加 Options -Indexes
作为文件内容。在添加 Options -Indexes
create a file named .htaccess
on that directory and add Options -Indexes
as the content of the file. Make sure you hit enter after adding Options -Indexes
之后,请确保按回车键,这将确保您的目录无法建立索引。即,您可以访问 www.mysite.com/uploads/file.pdf
这样的文件,但不能使用 www列出该目录中的所有文件。 mysite.com/uploads /
This will make sure that your directory will not be index able . i.e you can access the file say www.mysite.com/uploads/file.pdf
but you cannot list all the files in that directory using www.mysite.com/uploads/
这篇关于如何阻止对url目录的访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!