I want to restrict access to a complete website (apache 2.4) to certain IPs. On top of that I want to restrict access to certain subfolders to with user authentication. User auth is not working. Here is what I got:
In the vhost config I have
<Location />
# Localhost
Require ip 127.0.0.1i
# some other IP
Require ip 1.2.3.4
<Location>
Now I want the subfolder /secure/ to require a valid user login
<webroot>/secure/.htaccess
looks like
<RequireAll>
Require all granted
Require user user1 user2 user3
AuthBasicProvider file
AuthType Basic
AuthName "Secure Folder Login"
AuthUserFile /securePath/userAuth
</RequireAll>
I can still access /secure from the IP 1.2.3.4 without user authentication. It feels like apache matches the IP the Require ip 1.2.3.4
directive (inside implicid RequireAny
) and doesn't care about possible extra restrictions furhter down the line.
At least Location (out of Location, Directory, File and .htaccess directives) seem to be evaluated seperatly and last and in reverse order of appearance. I didn't check completely and I couldn't find docs on it.
Well long story short
I could achieve what I wanted by placing
below the
<Location />Require ip 1.2.3.4</Location>
block in the vhost config (above did not work). Using either<Directory>
block or.htaccess
did not work.