Password protected pages and WordPress (404 error)

I have recently been doing some work that I wanted to ring-fence in a password protected directory. The problem is, as soon as you put a password on a directlry WordPress gives a 404 error.

Ok, so wordpress is giving a 404 because it can’t find the directory you typed in, right?


The problem is actually not this at all. The problem comes from the rewrite engine WordPress uses to make search friendly URL’s. WordPress makes a .htaccess file in the root of it’s install (the root of my website, in my case) which looks like this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

Part of what this code does is takes any unknown URL and throws it at WordPress to sort out and server the appropriate page, or error.

In the case of my password protected page it wants to tell me about the 401 situation I am in (authentication) but my server has a default location for this, and there is no file there. When WordPress gets wind of this missing file it tries to be helpful and tell us about it, hence passing us a 404 error.

The Solution

The solution is actualy very simple. Open the .htaccess file and add the following before all the WordPress entries:

ErrorDocument 401 default

Save the file and retry to navigate to the protected directory. You will now get the popup box you were expecting in the first place, so you can enter your details and gain access as normal.

A very simple solution to a simple (but very confusing) problem.

3 replies
  1. Lyndi
    Lyndi says:

    Thanks Jim, this is something that has never been a problem for me thus far, but why wait till the problem arises? I have added the line to my .htaccess file so now the protected pages will be sorted out. This is also something you should suggest to the WP development team so that this could be added to the relevant file by default.

  2. Jim
    Jim says:

    Yeah, I may well suggest it, although I do wonder if there is a reason it is not there already, it just seems to make sense to me. It’s one of those irritating problems that, although the solution is simple, takes ages to figure out 😀

  3. sharp21
    sharp21 says:

    I realize this is an older post but I just ran across this exact problem!
    One question before I try your fix. The page I am trying to protect is also the page I have my posts on. Will this make a difference?


Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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