Solving 404 Errors When Using Htpasswd

Solving 404 Errors 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.

Troubleshooting

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!

Author

  • Nick Savov

    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.

0 0 votes
Article Rating
Subscribe
Notify of
24 Comments
Oldest
Newest
Inline Feedbacks
View all comments
Andrew Champ
Andrew Champ
7 years ago

Thank you. That’s exactly what I didn’t. .htaccess wanted that 401 ErrorDocument.

anotart
7 years ago

Thank you! Just what I needed!

steve
steve
7 years ago

Glad to hear that helped, Anne

Satalink
Satalink
7 years ago

This was driving me mad! (Three Thumbs up to you sir!!!)

Art Mason
Art Mason
6 years ago

Solved my problem!! Thank you!

Raj
Raj
5 years ago

thanks, you save my life.

Will
Will
4 years ago

This just did the trick, thought I was losing my mind. Thank you

Matthew
Matthew
4 years ago

Thanks!

Steve
Steve
4 years ago

So many hours wasted before finding this quick and easy fix… Thank you, sir!

Sam
Sam
4 years ago

Wow, how did you figure that out?? 🙂
Nice work..

Mohamad
Mohamad
4 years ago

Thank you very very much!

mikall
3 years ago
Reply to  Mohamad

You’re very welcome!

isak
isak
4 years ago

I think this may be what I need to resolve my problem: when I log in, I find myself in an endless loop to login and nothing has been changed since I was last able to log in. So… my questions: 
1.) do I need to only change the “path/to/passwd” part (and not the “Secured Area”)? 
2.) If so, where do I find this path/to/password? 
Thanks much.

Tester
Tester
4 years ago

Thanks for this article, it was really helpful.

mikall
3 years ago
Reply to  Tester

excellent!

Yordan Radev
Yordan Radev
3 years ago

Say I protected a website on an Apache server through an htaccess file, how would I allow for sub URLs to prompt for the login as well? Right now only example.com/ prompts for password and if try example.com/about it gives me a  Not Found

The Z Man
The Z Man
3 years ago

Thanks for the solution!

mikall
3 years ago
Reply to  The Z Man

So glad you found answers here at OST!  Thanks for posting.

Alex
Alex
3 years ago

1 million thumbs up

mikall
3 years ago
Reply to  Alex

Awesome! Very happy to be of help.

Mohamad
Mohamad
3 years ago

Thanks alot!

mikall
3 years ago
Reply to  Mohamad

You’re welcome!

wisam
wisam
2 years ago

Thanks

Logan
Logan
2 years ago

thanks so much I needed that last line. 

24
0
Would love your thoughts, please comment.x
()
x