<Directory "/path-to-protected">
AuthType Basic
AuthName "auth"
AuthUserFile "/auth-user-file-path"
require valid-user
SetEnvIf Request_URI "path-to-allow" allowed_restricted
Order allow,deny
Allow from 1.2.3.4 # allow from some ips
Allow from env=allowed_restricted # allow from some urls
Satisfy any
</Directory>