Apache configuration: Regex to disable access to files/directories beginning with a 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?
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)
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>
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>