Apache的配置:正则表达式来禁止访问的文件/目录以点开始 [英] Apache configuration: Regex to disable access to files/directories beginning with a dot

查看:785
本文介绍了Apache的配置:正则表达式来禁止访问的文件/目录以点开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要禁止访问任何文件或目录,名称以一个点。我想出了以下,但它禁止访问的文件/目录与DOT开头,只有当他们直接在文档根。

I want to disable access to any file OR directory, whose name begins with a DOT. I came up with the following but, it disables access to files/directories beginning with DOT only if they are directly in the Document root.

<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

请告诉我正确的正则表达式来实现这一目标?

Whats the proper regex to achieve this?

谢谢,

JP

推荐答案

您code不起作用,因为&LT;文件&GT; 仅适用于的基本名的要求的文件。即,在最后的斜线后的部分。 (来源:<一个href=\"http://httpd.apache.org/docs/current/mod/core.html#files\">http://httpd.apache.org/docs/current/mod/core.html#files)

You code does not work because <Files> only applies to the basename of the requested document. That is, the part after the last slash. (source: http://httpd.apache.org/docs/current/mod/core.html#files)

阿帕奇块的.htaccess 在默认安装文件(最好:所有文件开头 .HT )。如果在配置文件中仔细观察,你会看到这样的内容:

Apache blocks .htaccess files in a default installation (better: all files starting with .ht). If you looked closely at the configuration files, you would see something like this:

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

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

So to hide all files starting with a dot, you would use:

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

为了让它启动以点目录工作,请使用以下(测试)code:

In order to make it work for directories starting with a dot, use the following (tested) code:

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

这篇关于Apache的配置:正则表达式来禁止访问的文件/目录以点开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆