Solution for Password Protected Directories and WordPress

Teli Adlam —  June 13, 2007

Chances are, if you created a password protected directory alongside your WordPress installation, trying to access it lead to you to a WordPress 404 error (which may just look like the homepage of your blog if you don’t have a custom 404 error template file).

Well, there’s a solution. Initially, I found one solution at DianeV’s Developed Traffic which lead me to Ju-Ju which eventually lead to the TextPattern FAQ. It seems that TXP users were experiencing the same problem, and it’s because of an improper error document directive.

To get your password protected directories working again, create two files: 401.html and 403.html (they can be completely blank if you like). Then, add the following to your .htaccess file:

ErrorDocument 401 /[path_to_file]/401.html
ErrorDocument 403 /[path_to_file]/403.html

Save the changes and upload your new .htaccess file before your WordPress rewrite rules. Note: if you add these lines inside the WordPress rewrite rules, they will be overwritten each time you update your permalinks or made modifications which affects .htaccess in WordPress.

Remember: always make a back up of your files before making significant changes.

Side Note: If you don’t care to leave those two files blank, then simply put a friendly error message in each.

Error 401 is when the server requires authentication and it hasn’t been provided yet or the previous session is expired.

Error 403 is a way of saying that access to the directory is forbidden for whatever reason and it’s the one a person is likely to see if the login was incorrect or the authentication process was canceled.

[tags]wordpress 404 error, wordpress htaccess, wordpress password protected directories[/tags]

Teli Adlam