How to fix Password-protected directories on a WordPress blog
Here’s something I’d been struggling with for the better half of the day. I’ve been trying to get my server to password-protect a directory, since one of the Confidentiality rules I have to follow includes not posting work publicly. And yet, the only way I can do some of the work is by putting it on a public web server. Sorry. You don’t need to know that. You just need to know what happens and how to fix it. Well, here we go.
So, you used a site like Dynamic Drive to create your .htpasswd file. You added the following code to your .htaccess file.
AuthName "My Confidential Folder So You Cannot Steal Company Data"
You load up the directory, and what do you get?
Well now what do you do? If you’re like me, your next steps are something similar to:
- stare at monitor incredulously
- wash hands
- double-check everything
- triple-check everything
- curse the site
- write to support who don’t seem to help
- write on a message board, who tell you to try a different method (which, long story short, doesn’t work)
- read wordpress forums and don’t get anywhere because the solutions don’t work
- tear out no less than 5% of your hair in frustration
And then you eventually find your way here.
The reason you’re getting your fancy 404 page is because the first thing that happens on the server is that it looks for the 401 Error Code page and can’t find it. Now, in cPanel you can define your own custom error pages. Or you could pop open your webpage-creating IDE and create basic custom error pages, like 401.shtml and 500.shtml, and then upload them.
And then on the off chance you’re still having problems, you can edit your current .htaccess file to define the custom error pages.
ErrorDocument 401 /401.shtml
ErrorDocument 403 /403.shtml
ErrorDocument 404 /404.shtml
ErrorDocument 500 /500.shtml
And why do I like this method? Because I don’t have to log in to cPanel, find the icon that lets you define the custom error pages, and then methodically recreate each HTML file.
I mean, you created the files in Dreamweaver (or your preferred software) already. Why should you go through those steps above and then copy/paste the HTML into the files, when all you have to do is hit the Upload button?
So, that’s what I spent all day trying to solve. And if I can help someone with their problems, then I’ll feel like I’ve actually accomplished something.