Search code examples
apache.htaccesshttpd.conf.htpasswd

Allow either users OR ips to access using apache


I have users in .htpasswd and allowed IPs in .htaccess I want to allow either user/password (for IPs not in .htaccss) OR IPs to access (without auth).

I edited the dir section in httpd with these lines But its asking for user/password for the allowed IPs and IPs not in the file are not asked to authenticate.

<Directory xxx>
    AllowOverride All
    Options Indexes FollowSymLinks
    AuthName "Authentication required!"
    AuthType Basic
    AuthUserFile <my path>/.htpasswd
    <RequireAny>
        Require ip 127.0.0.1
        Require valid-user
    </RequireAny>
</Directory>

Solution

  • These configs worked for me

      AllowOverride All
      AuthType Basic
      AuthName "Authentication Required"
      AuthUserFile "/my path/.htpasswd"
      Require valid-user
      satisfy any
      deny from all
      allow from x.x.x.x