How to protect folders using a .htaccess

How to protect folders using a .htaccess

Through the file .htaccess you can protect any directory in your hosting account.
 
1.- How to create and where to place a .htaccess and .htpasswd file 
To create a .htaccess or .htpasswd file, open Notepad and enter the required code. Save the file as a text file (.txt), for example "htaccess_file.txt", and upload it via FTP to the folder where it needs to be used. Once on the server, rename the file "htaccess_file.txt" to ".htaccess". Do the same with the .htpasswd file.
 
Important: if you already have a .htaccess file inside your hosting account, you can use it by adding the new content. Otherwise, you might overwrite it and lose the current content.
 
2.- Configuring the content of the files 
In the .htpasswd file you must enter code similar to the following:
 
user:Jy.Wu9Uw3b99c
 
Where "user" is the username you define and that will be requested when accessing the folder, and where "Jy.Wu9Uw3b99c" is the encrypted password.
 
To create the content of this file, you have a tool available that generates the complete information:
 
Once you have the .htpasswd file with the correct code, create a .htaccess file with the following code:
 
AuthUserFile /absolute/path/web/directories/.htpasswd
AuthName "Authentication required"
AuthType Basic
require user user
 
  • AuthUserFile: is the full path where the .htpasswd file is located. From the Control Panel, in the hosting management section, you have an icon called "Server information". There you can see the root path of your hosting account under the field "Home directory".
    If you want to protect the root directory (web), the path is: /home/example.org/web/.htpasswd
    If you want to protect a subdirectory inside the root directory (web), the path is: /home/example.org/web/directory_name/.htpasswd
  • AuthName: is the message that will appear in the window requesting the username and password.
  • Require User: is the username to be entered. It is the user you specified in the .htpasswd file and the one that will be requested when accessing the protected directory.

 Once the .htaccess and .htpasswd files have been created and placed correctly, user authentication will be required every time someone attempts to access the protected directory.
 
 
For more information, you can contact us.
    • Related Articles

    • Information and uses of the .htaccess file

      1.- What is a .htaccess? The .htaccess (hypertext access) file is the default name for Apache’s directory-level configuration file. It is used to customize the configuration of directives and parameters defined in the main hosting configuration file. ...
    • How to protect folders with username and password

      If you want only the users you choose to access a folder in your hosting account, you can protect it with a username and password. In the cdmon Control Panel you can activate this protection. To do so, access the hosting management and in the ...
    • .htaccess default from PrestaShop

      The .htaccess file is a configuration file used on Apache-based web servers. It is used to control and configure the behavior of a website. The .htaccess file has multiple functions and allows you to customize a website’s configuration in a specific ...
    • How to use the cdmon cache tool

      Server cache is a key tool for improving the speed and efficiency of your website. In essence, it works by storing copies of your site's pages and resources in a quick access location, reducing the need to load them from scratch whenever someone ...
    • How to modify hosting file permissions

      From the cdmon Control Panel, in the hosting management, you can modify the permissions of your website's files and directories. To change permissions, in the 'Security' section click on the option File and folder permissions In this section you can ...