Jason Vertucio

I did a thing!

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.

The Problem

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"
AuthUserFile ".htpasswd"
AuthType Basic
Require valid-user

You load up the directory, and what do you get?

Not FoundThe requested URL /dig was not found on this server.

Apache/1.3.42 Server at mysite.com Port 80

Well now what do you do? If you’re like me, your next steps are something similar to:

  1. stare at monitor incredulously
  2. wash hands
  3. double-check everything
  4. triple-check everything
  5. curse the site
  6. write to support who don’t seem to help
  7. write on a message board, who tell you to try a different method (which, long story short, doesn’t work)
  8. read wordpress forums and don’t get anywhere because the solutions don’t work
  9. tear out no less than 5% of your hair in frustration

And then you eventually find your way here.

A Solution

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.