Question
Can I password-protect a directory using the cPanel interface?
Answer
You can password-protect a directory using the Directory Privacy feature in the cPanel interface. This feature uses .htaccess and htpasswd configurations to limit access to specific files and directories on your websites. Note that this will also limit access to subdirectories within the password-protected directory.
When using the Directory Privacy feature to password-protect a directory, the following rules are added to the .htaccess file in the password-protected directory. (If the .htaccess file does not exist, the file will be created.)
AuthType Basic
AuthName "Example"
AuthUserFile "/home/$USER/.htpasswds/Path/To/ProtectedDirectory/passwd"
Require valid-user
Note that .htaccess rules added by common Content Management Systems, such as WordPress or Joomla for example, may conflict with the .htaccess rules added by Directory Privacy. This may cause a 404 error when accessing the password-protected directory in a browser. If this occurs, you can try creating a file named "401.html" in the document root of the Content Management System and add the following to the .htaccess file in the password-protected directory: ErrorDocument 401 /401.html
Example:
ErrorDocument 401 /401.html
AuthType Basic
AuthName "Example"
AuthUserFile "/home/$USER/.htpasswds/Path/To/ProtectedDirectory/passwd"
Require valid-user
Further information can be found in our documentation: