Thursday, December 18, 2014

.htaccess and .htpasswd leads to 404 error

When you have .htaccess and .htpasswd to protect a folder on the server like this:

.htaccess:
AuthName "Restricted Area"
AuthType Basic
AuthUserFile /path/to/.htpasswd
AuthGroupFile /dev/null
require valid-user
.htpasswd:
user:password
Possibly it will be a 404 error when you access the folder from the web. Deleting .htaccess and .htpasswd, it will be fine again.

This is because Apache tries to look up the 401 document or whatever when it can't locate it. Just add this line to the end of .htaccess and the problem will go away.

.htaccess:
AuthName "Restricted Area"
AuthType Basic
AuthUserFile /home/thedatap/public_html/captain/.htpasswd
AuthGroupFile /dev/null
require valid-user
ErrorDocument 401 "Authorization Required"
 That's it. Try again and it will work now!

No comments:

Post a Comment