Is it possible to get the matched regex from within the apache LocationMatch directive?

Posted by tftd on Server Fault See other posts from Server Fault or by tftd
Published on 2012-09-03T14:52:27Z Indexed on 2012/09/03 15:40 UTC
Read the original article Hit count: 150

Filed under:
|

I'm wondering if the following code should be working:

<LocationMatch "/(.*)([/])?(.*)">
    Order allow,deny
    Allow from all

    AuthType Basic
    AuthName "Git"
    AuthUserFile  /git/.htpasswd
    AuthGroupFile /git/.htgroup
    Require group $1
</LocationMatch>

What I am trying to achieve with this is to require a group based on the first regex variable. So if the user goes to http://localhost/a-repository-name he has to be in the group a-repository-name to be able to open the url.

For some reason I can't get this code working and apache returns: Authorization of user **** to access /a-repository-name failed, reason: user is not part of the 'require'ed group(s).
I guess it's not matching against the proper variable at Require group $1.
Is this the right way to be done or I'm missing something?

© Server Fault or respective owner

Related posts about apache2

Related posts about regex