NixUser

NixUser.com | Unix User | Linux User | NixUser

Password protect directory or folder in wordpress installed directory

How to password protect a directory or files within WordPress installed directory?

To do this, you need to create a file named 401.html and edit the .htaccess file in the password protected directory.

Create the 401.html file in a separate directory (or in root directory) than the password protected directory.

In this case I created a /docs directory and created the 401.html file in there and added the following error message in the 401.html file.

AUTHENTICATION REQUIRED<br />You need a username and password to access this area.

Now edit the htaccess file in the password protected directory, say files.

vi files/.htaccess

The authorization rules for password protection should already be added in the htaccess file. Above the rules add the following line.

ErrorDocument 401 /docs/401.html

Save and exit the file editor and you should be able to access the directory password protected.