this is Apache httpd 2.4.
I am trying to port a legacy installation from 2.2 to 2.4 and clean it up a bit in the process. There are a lot off directories with identical setup, interspersed with a few dirs that differ. In essence, it looks like this:
<directory /var/www/aaa >
# lots of stuff
</directory>
<directory /var/www/bbb >
# lots of stuff
</directory>
<directory /var/www/ >
# lots of stuff
</directory>
<directory /var/www/ccc >
# lots of other stuff
</directory>
I'd love to avoid redundant lines, so I'm wishing for some sort of shorthand, like:
<directory /var/www/aaa >
<directory /var/www/bbb >
<directory /var/www/ >
# lots of stuff
</directory>
<directory /var/www/ccc >
# lots of other stuff
</directory>
But <Directory>
doesn't support multiple dirs in any way that I can find. So <DirectoryMatch>
seems appropriate, like this:
<directoryMatch /var/www/(aaa|bbb|) >
# lots of stuff
</directory>
<directoryMatch /var/www/ccc >
# lots of other stuff
</directory>
This fails, as the /var/www/(aaa|bbb|)
matches /var/www/ccc
in partial. And contrary to <Directory>
, <DirectoryMatch>
is not processed in the order shortest directory component to longest. The manual claims that "within each group the sections are processed in the order they appear in the configuration files", but even if I switch the sections, the result is still the same (that /var/www/ccc
is hit by "# lots of stuff
" instead of by "# lots of other stuff
").
In this example, I can of course extend the regexp (/var/www/(aaa|bbb|(?!ccc))
), but the real configuration is unfortunately much more complex than this. Working with the regex is probably still a possibility, but the result will hardly be easy to understand or maintain.
So can someone give me a hint if there is some way to do this, beside the DirectoryMatch? And perhaps an explanation for why Apache seems to prefer the partial match above? Thanks.
/var/www/(aaa|bbb|)
, use^/var/www/(aaa|bbb|)/
– wurtel May 02 '19 at 14:33Directory
? Maybe there is a simpler solution, because<Directory /var/www/>
also matches everything below this directory like/var/www/aaa
... – Freddy May 02 '19 at 18:42