Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can regex capture and substitution be used with an Apache DirectoryMatch directive?

Tags:

regex

apache

Does anyone know if it's possible to use regex capture within Apache's DirectoryMatch directive? I'd like to do something like the following:

<DirectoryMatch ^/home/www/(.*)>
    AuthType Basic
    AuthName $1
    AuthUserFile /etc/apache2/svn.passwd
    Require group $1 admin
</DirectoryMatch>

but so far I've had no success.

Specifically, I'm trying to create a group-based HTTP Auth for individual directories/vhosts on a server in Apache 2.0.

For example, Site A, pointing to /home/www/a will be available to all users in group admin and group a, site b at /home/www/b will be available to all users in group admin and group b, etc. I'd like to keep everything based on the directory name so I can easily script adding htpasswd users to the correct groups and automate this as much as possible, but other suggestions for solving the problem are certainly welcome.

like image 735
Chris Avatar asked Oct 26 '22 08:10

Chris


1 Answers

You could tackle the problem from a completely different angle: enable the perl module and you can include a little perl script in your httpd.conf. You could then do something like this:

<Perl>
my @groups = qw/ foo bar baz /;
foreach ( @groups ) {
    push @PerlConfig, qq| <Directory /home/www/$_> blah </Directory> |;
}
</Perl>

That way, you could even read your groups and other information from a database or by simply globbing /home/www or whatever else tickles your fancy.

like image 189
innaM Avatar answered Oct 29 '22 23:10

innaM