I am trying to configure Apache v2.4.7 to lookup in a database if a user can access a specific location. I manage to do it for a few specific location, but fail to do it for dynamic locations.
So this is what works for two locations "mydomain.com/foo" and "mydomain.com/bar"
<Location /foo>
AuthName "/foo"
AuthType Digest
Require valid-user
AuthBasicProvider dbd
AuthDBDUserRealmQuery "SELECT password FROM Users WHERE login = '%s' AND realm = '%s'"
</Location>
<Location /bar>
AuthName "/bar"
AuthType Digest
Require valid-user
AuthBasicProvider dbd
AuthDBDUserRealmQuery "SELECT password FROM Users WHERE login = '%s' AND realm = '%s'"
</Location>
This is working fine if I have a record for realms "/foo" or "/bar" in my database.
But now, let's say I have a thousand of them, and some can be created anytime. I tried the following solution:
<LocationMatch /.*>
AuthName "%{DOCUMENT_URI}"
AuthType Digest
Require valid-user
AuthBasicProvider dbd
AuthDBDUserRealmQuery "SELECT password FROM Users WHERE login = '%s' AND realm = '%s'"
</LocationMatch>
I read (https://httpd.apache.org/docs/trunk/fr/mod/mod_authn_core.html#authname) that AuthName
can be dynamically set but I keep getting the following message in the error log, which means that the variable is not being replaced dynamically by the actual requested location.
user `firstname.lastname' in realm `%{DOCUMENT_URI}' not found:
I would appreciate some help to find what is it I am doing wrong, or find another way.