Authentication will be transmitted without protection over the network if you use the standard http protocol. This is not considered safe, as someone might sniff a password.
If you restrict access to https, it is completely safe. This would mean installing and activating the apache module for ssl encrypted http traffic (port 433, https: // in the address bar of the browser) and disabling standard http traffic for this directory on port 80. The username and password will be ssl encrypted. Be sure to choose a good password (long enough and complicated, impossible to guess or brute force).
Configuring Apache can be a daunting task, so take great care to keep it simple and check for possible errors.
It might be a good idea to move the access restriction configuration from the .htaccess file to the main apache configuration file if you have knowledge and control over it. It might also be easier for you to save it in a .htacces file. And โeasyโ can be safer. Make it look simple and safe, easy to maintain and memorable for you.
This is a simple setup to increase safety and protect against accidents:
If you have php and email configured on the computer where the protected directory is, you can write a simple alarm script. Just a php file "alarm.php" with one line with the php mail function that sends you an email informing you that htaccess protection is not working.
If your path to the domain and directory is โ http://mybox.example.com/secretdir/alarm.php , you can enter it in a browser on another machine, and you should receive this mail while htaccess is open. If it is protected , you can enter your username and password and you will also receive mail.
To do an automatic alarm, you can use another unix block that tries to get this URL every 15 minutes or so. Line for crontab:
* / 15 * * * * user1 wget http://mybox.example.com/secretdir/alarm.php
user1 is the user on this computer who is allowed to run wget, and wget must be installed.
You can disable htaccess protection as a test and receive mail every 15 minutes.
In my experience, a common security flaw is that a directory that you think is protected loses its protection when you change something, and you donโt know, this way you get a message that warns you.