On my development machine osx-sierra / apache 2.4.10 (from brew) I have a restriction in a VirtualHost that allow access to /api/ without password, and all others pages need the password with this code:
<Location />
AuthType Basic
AuthName "Access"
AuthUserFile /Users/xxxxxx/www/public/.htpasswd
Require expr %{REQUEST_URI} =~ m#^/api/*#
Require valid-user
</Location>
When I try to do it on my production server with the same directives, Debian-jessie / apache 2.4.29 (from apt), it doesn't work, password is always ask (chrome/safari/wget), I tryed theses solutions :
1/
<Location />
AuthType Basic
AuthName "Access"
AuthUserFile /home/xxxxxx/www/public/.htpasswd
Require expr %{REQUEST_URI} =~ m#^/api/*#
Require valid-user
</Location>
2/
<Location />
AuthType Basic
AuthName "Access"
AuthUserFile /home/xxxxxx/www/public/.htpasswd
Require expr %{REQUEST_URI} =~ m#^/api/.*#
Require valid-user
</Location>
Any idea of why these differences ?
Thanks
I'm not sure why that would work on osx-sierra / Apache 2.4.10, but not seemingly on Debian-jessie / Apache 2.4.29. However, as a workaround you could do this a different way using a negative lookahead on a
<LocationMatch>
container instead of using Apache 2.4 expressions. For example:Now, the directives inside the
<LocationMatch>
container are only processed when the URL does not start/api/
. (This also works on Apache 2.2)This is the complet virtualhost where directives do not work :
Why complicate it so much instead of doing it straightforward?
Also note, your previous Directory (the documentroot directory) directive mixing 2.2.x and 2.4.x directives could be screwing everything up.
A mess:
The correct thing to do: