htaccess password protection with ip whitelisting

PHOTO EMBED

Mon Jun 07 2021 16:04:09 GMT+0000 (UTC)

Saved by @dphillips #htaccess #webserver #http

# apache < 2.4

AuthUserFile /var/www/mysite/.htpasswd
AuthName "Please Log In"
AuthType Basic
require valid-user
Order allow,deny
Allow from 5.10.171.77
satisfy any

# apache >= 2.4

<If "%{REMOTE_ADDR} != '5.10.171.77'">
  AuthType Basic
  AuthName "Please Log In"
  AuthUserFile /path/to/.htpasswd
  require valid-user
</If>
content_copyCOPY

AuthUserFile must be an absolute path.

https://stackoverflow.com/questions/10419592/htaccess-htpasswd-bypass-if-at-a-certain-ip-address