An .htaccess directive is basically a command that is specific to a module or built-in to the core that performs a specific task or sets a specific setting for how Apache serves your website.
Directives placed in htaccess files apply to the directory they are in, and all sub-directories.
Main Directives in htaccess
Most important directives are:
These allow you to restrict access, or grant access, to specific folders, or files. It is also possible, through these directives, to give access to specific ip addresses or hosts.
For example, if you wanted to restrict access to jpeg files to the foo user, you would simply use the
Files directive along with the
AuthName "Title of Login Window"
<Files ~ ".*.jpg$">
Require user foo
Meaning of above code:
AuthNamedirective contains the tile that will be displayed in login window.
AuthUserFiledirective contains the absolute path to the file containing the users.
AuthTypedirective indicates the type of authentication that Apache should perform.
Require valid-userdirective tells Apache that the folder and subfolders and the files contained in them will be accessed by all users specified in the users file.
Filesdirective forces Apache to require the user named foo to perform the display of files with the jpg extension.
To create .htpasswd files, you can use apache's htpasswd utility.