Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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?

share|improve this question
up vote 2 down vote accepted

LocationMatch doesn't support backreferencing, you can't do that in versions before 2.4.8.

share|improve this answer
Can you please provide a link in the documentation where this is stated? I changed Require group $1 to Require group mygroup and it worked perfect. – tftd Sep 3 '12 at 15:04
@tftd: Changed the wording. I meant regexp grouping, not the group you set in Require. – InternetSeriousBusiness Sep 3 '12 at 15:07
Is there any known workaround? – tftd Sep 3 '12 at 15:30
@tftd: I'm afraid you'll have to attack the problem from another angle. – InternetSeriousBusiness Sep 3 '12 at 17:12
Okey, thanks for the help! :) – tftd Sep 3 '12 at 20:28

According to the Apache documentation this is now supported...

From 2.4.8 onwards, named groups and backreferences are captured and written to the environment with the corresponding name prefixed with "MATCH_" and in upper case. This allows elements of URLs to be referenced from within expressions and modules like mod_rewrite. In order to prevent confusion, numbered (unnamed) backreferences are ignored. Use named groups instead.

<LocationMatch "^/combined/(?<sitename>[^/]+)">
    require ldap-group cn=%{env:MATCH_SITENAME},ou=combined,o=Example
share|improve this answer
Wow! Thank you for answering such an old question! I'm glad they've included this in the newer versions. Unfortunately I can't accept your answer because the original answer was valid at the time. – tftd Sep 21 '15 at 14:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.