Password protected pages and Wordpress (404 error)

Technical Info Add comments

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?

WRONG!

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]
</IfModule>
# END WordPress

Part of what this code does is takes any unknown URL and throws it as 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.

Stumble it!

2 Responses to “Password protected pages and Wordpress (404 error)”

  1. 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 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 :D

Leave a Reply