WordPress: Password-Protected pages not working on folders within WordPress’ directory (Error 404)

Symptoms: You add password-protected directories to folders within your WordPress installation, but instead of showing a password-protection prompt, your browser will show a 404 page instead

This appears to be a common issue for users that try to password-protect folders within an installation of WordPress.
This happens because you did not define a 401/403 (depending on the situation) error page in your main .htaccess file.

In order to correct this, you will need to add the 401 error page to your WordPress’ .htaccess file.
Example of a WordPress .htaccess file:

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

In order to correct this issue, simply create a 401 and 403 error page (on this example I’m using errors/401.html) and add it to .htaccess:

ErrorDocument 401 /errors/401.html
ErrorDocument 403 /errors/403.html

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

And that’s it, save .htaccess and your password-protected folders should work now.

One Response to “WordPress: Password-Protected pages not working on folders within WordPress’ directory (Error 404)”

  • Chris:

    Very helpful. Had a similar problem with cpanel hosting failing to protect directories – had to be something in the main page htaccess file for CMS Made Simple but could not work out what. This tip did the trick although I have to say I do not understand why! Many thanks for sharing.

Leave a Reply