Knowledgebase: Web Hosting Related
Why do I get a 404 not found error in wordpress when I password protect a directory?
Posted by Support, Last modified by Support on 08 April 2014 01:19 PM

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]
# 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. Download the .htaccess file where Wordpress is installed via FTP, open it and add the following before all the Wordpress entries or modify the current ErrorDocument 401 line to the following:

ErrorDocument 401 default

Save the file, re-upload it via FTP 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.

(644 vote(s))
Not helpful