How do I password protect a directory within the public_ssl folder? Print
Submit Cancel
Email this article

Close

You are here: Home > Website Support > .htaccess Config

Password protecting a directory can be done with the use of a .htaccess file. The steps below will allow you to protect access to a directory on the server for your domain via the web browser:

  1. Connect to your hosting server via SSH.
  2. Execute the following command and replace the relevant entries with your domains details:
  3. htpasswd -/usr/wwws/users/FTP_USERNAME/.htpasswd USERNAME_FOR_DIRECTORY 
    Note: The above is entered on a single line.
  4. You will be prompted for a password to protect the directory with that will be used in conjunction with the above specified username.
  5. If the above steps were actioned successfully you should see the following output:
    Adding password for user USERNAME_FOR_DIRECTORY 
  6. Create a “.htaccess” file within the folder you wish to protect using a text editor such as “nano” e.g
    cd My_directory_to_protect
    nano .htaccess 
  7. Note: The above is entered on a single line.
  8. Insert the below lines into your “.htaccess” file and ensure to replace the “AuthUserFile” with the location in which your placed the “.htpasswd” file:
    AuthName "Title of prompt seen in web browser"
    AuthType Basic
    AuthUserFile 
    /usr/wwws/users/FTP_USERNAME/.htpasswd
    require valid-user 
     
  9. Save the file and exit nano by using the keys:
    CTRL o
    and then
    CTRL 
  10. Test the access to your folder by requesting the folder via your web browser, i.e https://www.your-domain.co.za/protected_directory/, you should then be prompted for your username and password.

Was this information helpful?

Yes No

Thank you for your feedback
We are delighted to find that our article resolved your query.

Thank you for your feedback
We will resolve your query as soon as possible.

Please take a few moments to comment on your unresolved query. Simply tell us what your problem is. We guarantee that we'll get back to you within two hours (during office hours) in response to your query.


  Partially resolved    Unresolved
Enter your query here:
Your name:
Your email address:
Contact number:
Customer number or domain name:
 
Preferred contact method: Email     Call me
Please enter the text in the picture below into the text box:
CAPTCHA Image:
ID Number:
 
  • Hosting for Beginners

    Step-by-step guide to hosting with Hetzner.

    VIEW NOW
  • Application Tutorials

    Use our installation guides to get up and running.

    VIEW NOW
  • Login Now

    Our award winning proprietary control panel empowers customers to manage their hosting environment.

    Take the Tour
  • Contact Us

    support@hetzner.co.za

    Phone: 0861-0861-08
    Fax: 0861 0861-09
    Contact Us