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
Blog Rating
Subscribe
Notify of
24 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Andrew Champ

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

anotart

Thank you! Just what I needed!

steve

Glad to hear that helped, Anne

Satalink

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

Art Mason

Solved my problem!! Thank you!

Raj

thanks, you save my life.

Will

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

Matthew

Thanks!

Steve

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

Sam

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

Mohamad

Thank you very very much!

mikall

You’re very welcome!

isak

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

Thanks for this article, it was really helpful.

mikall

excellent!

Yordan Radev

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

Thanks for the solution!

mikall

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

Alex

1 million thumbs up

mikall

Awesome! Very happy to be of help.

Mohamad

Thanks alot!

mikall

You’re welcome!

wisam

Thanks

Logan

thanks so much I needed that last line. 

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