我有以下文件夹结构:PHP文件和文件夹结构显示,需要隐藏它
+users
-adduser.php
-viewuser.php
当访问者浏览到example.com/users
它显示的文件夹结构。我需要限制访问者查看文件列表的能力,通过隐藏或删除它。我怎么能在PHP中做到这一点?
我有以下文件夹结构:PHP文件和文件夹结构显示,需要隐藏它
+users
-adduser.php
-viewuser.php
当访问者浏览到example.com/users
它显示的文件夹结构。我需要限制访问者查看文件列表的能力,通过隐藏或删除它。我怎么能在PHP中做到这一点?
如果您不想(或不能)处理Apache配置,请在您的用户中创建一个名为index.html(或index.php,如果您愿意)的空文件夹。
您可以使用以下方式在根文件夹上创建.htaccess文件;
RewriteEngine on
Redirect 301 /users http://www.example.com/404.html
然后,您只需要在您的网站上创建404.html并将您的网域更改为example.com。
现在你的/ users路径将重定向到404.html。
您可以添加以下到Apache的虚拟主机文件:
<Directory "path_to_folder">
Options -Indexes
</Directory>
以上规则将禁止目录列表。本帖子中提示:Using .htaccess, prevent users from accessing resource directories, and yet allow the sourcecode access resources
您可以根据[this other SO post](https://stackoverflow.com/questions/2530372/how-do-i-disable-directory-browsing)禁用索引,但取决于该文件夹中的内容,将它放在webroot之外可能会更好。 –
@JonStirling但是在部分开发过程中,如果每个东西都在根目录下,我们有正确的文件夹,这是不可理解的 –
对不起,无法计算出您要评论的内容。 –