使用 .htaccess 隐藏文件夹
是否可以隐藏根文件夹中的文件夹? 以防我的index.php消失你知道吗?
如果有人请求,我还可以显示 404 错误未找到吗?
Is it possible to hide the folders in my root folder?
Just in case my index.php would disappear you know?
Could I also show 404 error not found if someone requests them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
您想要的可能是,
如果没有找到 DirectoryIndex 文件,只会给出 404 错误。
What you want is probably
which will just give a 404 error if no DirectoryIndex file is found.
以上将阻止列出所有文件。这里
*
充当通配符。如果需要,您可以将其替换为更具体的内容。The above would prevent all files from being listed. Here
*
acts as a wildcard. You could replace it with something more specific, if needed.正如 duskwuff 所提到的,您需要的是
这将在该特定目录上导致 403 禁止错误。因此,要提供自定义错误页面,您将需要
希望这有帮助
As mentioned by duskwuff, what you need is
This will cause a 403 forbidden error on that particular directory. Thus to provide a custom error page you will need
Hope this helps
如果您确实想显示子文件夹的 404 错误,请在
/.htaccess
中尝试以下操作:如果存在
/folder
或/subfolder ,则上述规则会将其重写为
/404
。If you really want to show a 404 error for subfolder(s) , try the following in
/.htaccess
:If an existent
/folder
or/subfolder
is requested, the above rule will rewrite it to/404
.我通过在我不想访问的所有文件夹上添加一个index.html 来解决这个问题。 index.html 页面包含一行,其中包含以下
header("Location:thepageiwanttoshown.html")
。这样,如果用户意外访问受限文件夹,他们将被即时重定向。我希望它有帮助I get around this by adding an index.html on all folders i dont want accessed. The index.html page contains a single line with the following
header("Location:thepageiwanttoshown.html")
. This way if the user accidentally visits the restricted folders they will be redirected on the fly. I hope it helps这是我针对同一问题的首选解决方案(不过,这会显示拒绝访问而不是 404):
这还为您提供了授予对某些 IP 的访问权限的选项(在这种情况下,它拒绝对所有 IP 的访问)
“/path/to/如果您想使用模式,则可以将“single/file/or/folder”替换为正则表达式。否则,您必须对要阻止访问的每个特定文件或文件夹使用多个阻止。
This was my preferred solution to the same problem (this displays an Access Denied instead of 404 though):
This also gives you the option to give access to certain IP's (in this case it deny's access to all)
The "/path/to/single/file/or/folder" can be replaced with regex if you want to use a pattern instead. Otherwise you have to use multiple blocks for each specific file or folder that you want to block access to.
就我而言,我这样做了,但它显示错误 500。这是我的 .htaccess
谢谢
In my case, i did that but it shows me Error 500. This is my .htaccess
Thanks
对我来说,它总是可以添加
到文件 /etc/apache2/sites-available/default
For me it always works with adding
to the file /etc/apache2/sites-available/default
我使用了这段代码:
在你的主根 .htaccess 中放置以下代码:
I used this code:
At your main root .htaccess put the flowing code :
在要隐藏文件夹列表的目录中创建一个文件 mame .htaccess 并仅包含此代码
make a file mame .htaccess in the directory where you want to hide folder's list and just this code