Why is my .htaccess and .htpasswd not working?

AuthUserFile ./.htpasswd

The file-path to your password file is most certainly wrong. This should be an absolute filesystem path. (Or a relative path, relative to the ServerRoot).

For example, depending on the file-path to your document root, this should be something like the following instead:

AuthUserFile /www/user/public_html/images/.htpasswd

However, the .htpasswd file should be at a location outside of the DocumentRoot (outside of the public HTML space). It shouldn't be in the directory you are trying to protect.

Reference:

  • https://httpd.apache.org/docs/2.2/mod/mod_authn_file.html#authuserfile