| Coding Tutorials

Solving 404 Errors When Using Htpasswd

404 Error When Using Htpasswd

One of our Pro support members was having trouble getting into the admin section of his website. He was getting a 404 error. No recent changes had been made to the site and it was working fine a few days ago.

We debugged the issue for him and it ended up being an issue with an Apache update and an incompatible htaccess/htpasswd rule. This tutorial will show you the fix.


First off, I disabled the .htaccess file and checked the admin. It indeed worked after disabling the file. The last edit on the file was months ago, so nothing had changed for it recently. The htpasswd file also hadn't been changed in months.

Then I double checked the paths and those were all OK. Since nothing had changed, I suspected that it was a server issue of some kind.

The fix

It problem ended up being an Apache update and the new Apache version wasn't compatible with legacy htaccess rules. It needed the following:

ErrorDocument 401 "Authorisation Required"

So, this:

AuthType Basic AuthName "Secured Area" AuthUserFile "path/to/passwd" require valid-user 

Became this:

AuthType Basic AuthName "Secured Area" AuthUserFile "path/to/passwd" require valid-user ErrorDocument 401 "Authorisation Required"

What is that line doing? It's declaring the page to have a HTTP 401 error with a custom message of "Authorisation Required". The 401 error is required by Apache to trigger the htpasswd file.

I hope this tutorial gets you out of a jam!

About the author

Nick is the Director of Support at OSTraining and you can find him in almost every area of the site, from answering support requests and account questions to creating tutorials and software.