Securing a directory in DirectAdmin
In DirectAdmin it is quite easy to protect directories/folders with a username and/or password.
- Log in to the control panel.
- At the top right, choose FILES (the file explorer).
- Select the folder/directory you want to protect, i.e. in /domains/yourdomain.xx/public_html
- Next to the folder you will see PROTECT; click it.
- Next to Protected Directory Prompt, enter a name you will recognise; this will be shown at login.
- Set/Update User: enter a username and a password here.
- Finally, do not forget to tick Protection Enabled.
A .htaccess file will then be created in that folder with roughly the following content:
AuthGroupFile /dev/null
AuthName "De loginomschrijving"
AuthType Basic
AuthUserFile /home/account/domains/<uwdomein.xx>/.htpasswd/public_html/<directory>/.htpasswd
require valid-user
Protecting 1 or more files
It is also possible to protect a single file. However, you must first carry out the steps above on a directory so that this file is created: public_html/directory/.htpasswd. The directory itself does not matter much, but it is needed to easily add users with access rights via DirectAdmin.
After that you need to edit the .htaccess file manually (you can do this per:
<FilesMatch "voorbeeld.html">
AuthName "Member Only"
AuthType Basic
AuthUserFile /home/account/domains/<uwdomein.xx>/.htpasswd/public_html/<directory>/.htpasswd
require valid-user
</FilesMatch>
PLEASE NOTE: you must replace <uwdomein.xx> and <directory> with your own details.
You can also protect several files at once in this way.
