openaxcss
 

Why do I get a 404 not found error in wordpress when I password protect a directory?

Problem: Why when I password protect a sub-directory and try going to the folder WordPress gives a 404 error?

This problem comes from the rewrite engine WordPress uses to make search friendly URL’s. WordPress makes a .htaccess file in the root folder of it’s install 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 at WordPress to sort out and serve 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 actually very simple. Open and edit your htaccess and ADD the line below;
ErrorDocument 401 default

Save the file, and retry accessing 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

See it live in one of our web projects : http://gaiasouthinc.com/jude.

This site runs on wordpress.

 

Leave a Reply

You must be logged in to post a comment.

 
 
Esphil PMA clients