Apache offers you a secure and easy way to protect your directories, with .htaccess and .htpasswd files.
To prevent a web directory from being accessed from unauthorized users,
you will need to create both
a .htaccess and a .htpasswd
at the root of the directory to protect.
The .htaccess file must contain the following content:
AuthName "Protected directory!" AuthType Basic AuthUserFile /directory/to/protect/.htpasswd AuthGroupFile /dev/null require valid-user
Do not forget to replace the highlighted words
with the path you want to restrict!
Every line of the referred AuthUserFile contains the
login and the corresponding encrypted password
of an authorized user, separated by a semicolon.
To generate a properly cyphered .htpasswd,
you can use the tool on the left.
The generated file will look like this:
user:dXERdeoxy.t.Q anotheruser:aG8RI59z9ucgY