Preface
I'm very much a neophyte regarding webservers. I'm setting up an Apache2 server and currently poring over the documentation.
I noticed that the <Directory>
, <Location>
, and <Files>
directives each have a corresponding <*Match>
directive: <DirectoryMatch>
, <LocationMatch>
and <FilesMatch>
respectively. The difference on the surface is apparent enough:
<*Match>
directives take a regular expression as an argument- Non-Match directives take a plain string or shell-style glob as their argument.
Curiously, the non-Match directives can also be given a regular expression as their argument if it is preceded by a '~'. Thus, the following two lines ought to be identical:
# From the Apache2 docs
<Directory ~ "^/www/[0-9]{3}"> ... </Directory>
<DirectoryMatch "^/www/[0-9]{3}"> ... </DirectoryMatch>
Questions
What I'd like to know is whether or not there are any subtle or key differences to be aware of that Apache's core
docs do not mention. The <DirectoryMatch>
section does mention one subtle difference:
Compatibility
Prior to 2.3.9, this directive implicitly applied to sub-directories (like
<Directory>
) and could not match the end of line symbol ($). In 2.3.9 and later, only directories that match the expression are affected by the enclosed directives.
Beyond that, I would like to know:
- Are there any other differences between the Match and non-Match directives?
- Which directive is more preferable when a regular expression is required?
- Any other information you feel is pertinent?
Notes
<DirectoryMatch>
and<Directory "~">
are on the same merge level- While not explicitly mentioned,
<Directory "~">
can use named groups and backreferences, just like<DirectoryMatch>
.