gpt4 book ai didi

regex - Apache 配置: Regex to disable access to files/directories beginning with a dot

转载 作者:行者123 更新时间:2023-12-02 02:59:10 25 4
gpt4 key购买 nike

我想禁止访问任何名称以点开头的文件或目录。我想出了以下方法,但只有当它们直接位于文档根目录中时,它才会禁用对以 DOT 开头的文件/目录的访问。

<Files ~ "^\.|\/\.">
Order allow,deny
Deny from all
</Files>

有了这个,

http://my_server.com/.svn/entries   --> Permission denied
http://my_server.com/abcd/.svn/entries --> Accessible, should be disabled

实现此目的的正确正则表达式是什么?

最佳答案

您的代码不起作用,因为 <Files>仅适用于所请求文档的基本名称。即最后一个斜杠之后的部分。 (来源:http://httpd.apache.org/docs/current/mod/core.html#files)

Apache block .htaccess默认安装中的文件(更好:所有以 .ht 开头的文件)。如果仔细查看配置文件,您会看到如下内容:

<FilesMatch "^\.ht">
Order allow,deny
Deny from all
</FilesMatch>

因此,要隐藏所有以点开头的文件,您可以使用:

<FilesMatch "^\.">
Order allow,deny
Deny from all
</FilesMatch>

为了使其适用于以点开头的目录,请使用以下(经过测试的)代码:

<DirectoryMatch "^\.|\/\.">
Order allow,deny
Deny from all
</DirectoryMatch>

关于regex - Apache 配置: Regex to disable access to files/directories beginning with a dot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4352737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com