PHP文件和文件夹结构显示,需要隐藏它

时间:2017-07-04 10:20:19

标签: php .htaccess url

我有以下文件夹结构:

+users
   -adduser.php
   -viewuser.php

当访问者导航到example.com/users时,它会显示文件夹结构。我需要通过隐藏或删除文件列表来限制访问者查看文件列表的能力。我怎么能在PHP中做到这一点?

3 个答案:

答案 0 :(得分:0)

您可以使用以下内容在根文件夹上创建.htaccess文件;

RewriteEngine on
Redirect 301 /users http://www.example.com/404.html

然后,您只需在您的网站中创建404.html并使用您的域名更改example.com。

现在您的/ users路径将重定向到404.html。

答案 1 :(得分:0)

您可以将以下内容添加到Apache虚拟主机文件中:

<Directory "path_to_folder">
    Options -Indexes
</Directory>

上述规则将禁止目录列表。这篇文章建议:Using .htaccess, prevent users from accessing resource directories, and yet allow the sourcecode access resources

答案 2 :(得分:0)

如果您不想(或不能)处理Apache配置,请在users文件夹中创建一个名为index.html(或者如果您愿意更改为index.php)的空文件。