Knowledge base

1000 FAQs, 500 tutorials and instructional videos. Here, there are only solutions!

Secure web access with a password

Update 08/11/2026

This guide explains how to protect a section of a website on a Web Hosting plan by requiring a password to be entered before a directory (including subdirectories) can be accessed from a browser.

Please note that this does not prevent a user from accessing the directory via FTP.

 

Simple method

To password-protect (Digest authentication) a directory using the "Folder Protection" tool:

  1. Click here to access the management of your website on the Infomaniak Manager (need help?).
  2. Click directly on the name assigned to the website in question:
  3. Click on Security in the left-hand menu.
  4. Click on Folder Protection.
  5. Click on the directory you want to protect.
  6. Enable protection using the toggle switch, then create one or more users:
    • * Users are defined per directory; the tool does not allow you to manage user groups:
  7. Click the Add button.
  8. Click the button to Add access for an additional user if needed.
  9. Click on the action menu located to the right of the user you want to modify or remove.
  10. Click on the toggle switch again to completely disable directory protection:

 

Manual method via .htaccess

To protect a folder with a password using the .htaccess file of your site:

  1. Connect to your hosting via an FTP software/client or Web FTP.
  2. In the folder you want to protect, create a file called password.php and adapt the following content by replacing 12345 with the desired password:

    <?php
    $password = "12345";
    echo password_hash($password, PASSWORD_DEFAULT); // Displays the hashed password
    ?>
  3. Open a web browser and display the password.php file (example: domain.xyz/folder-to-protect/password.php).
  4. The web browser will display your encrypted password; copy the encrypted password, as you will need it later…

In the folder you want to protect, create a file called .htaccess and adapt the following content within it:

AuthName "Protected Administration Page"
AuthType Basic
AuthUserFile "/example/.htpasswd"
Require valid-user

Replace /example/ with the absolute path of the folder you want to protect. Example:

AuthUserFile "/home/clients/0f83c7afb710e5ae2645a1b704d8772f/web/protected_folder/.htpasswd"

In the folder you want to protect, create a file called htpasswd.txt and adapt the following content within it:

username:hashed_password
  • Replace username with the desired login.
  • Replace hashed_password with the encrypted password copied in step 1 of this guide.

Once the htpasswd.txt file has been saved, rename it as follows: .htpasswd.

Open a web browser and try to display one of the pages contained in the protected folder. If the instructions have been followed correctly, the login and password (not encrypted) you chose will allow you to access the protected folder.

Other restrictions may also be applied via .htaccess.


Has this FAQ been helpful?