I am trying to protect a folder from direct access with username and password on localhost under Apache webserver on Windows machine. According to this article, I've looked for DOCUMENT_ROOT
value in phpinfo results and found the following: C:/Program Files/Apache Software Foundation/Apache2.2/htdocs
.
Since my folder inside htdocs
is called protected
, I created the following htaccess file:
AuthType Basic
AuthName "restricted area"
AuthUserFile C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/protected/.htpasswd
require valid-user
and the following .htpasswd (user:test, password: test)
test:teH0wLIpW0gyQ
But when I try to access the folder, I receive an "Internal Server Error". Looking on Apache error log, I found the following line:
[Thu Mar 13 22:00:15 2014] [alert] [client 127.0.0.1] C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/protected/.htaccess: AuthUserFile takes 1-2 arguments, text file containing user IDs and passwords
What am I missing? I doesn't seem to be related to spaces in .htpasswd path, but something related to .htpasswd sintax. I would like to build something which can be used both on localhost and online.
UPDATE
Enclosing htpasswd path into inverted commas eliminates the error
AuthUserFile "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/protected/.htpasswd"
but unfortunately doesn't work (if I type user:test, password:test when required I receive a password mismatch error). See the following apache log:
[Thu Mar 13 22:26:43 2014] [error] [client 127.0.0.1] user test: authentication failure for "/protected/": Password Mismatch
Any ideas?