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
^/api/*
(as inm#^/api/*#
) is not strictly correct (at least I doubt it matches what you think it matches). I think you mean^/api/.*
(as in your second example). However, that last.*
is superfluous anyway and is the same as^/api/
. Although these tweaks to the regex won't make any difference to your real problem.