Apache/Security

Numerous robots use to try to crack some databases (for instance via or ). To be protected from them, we can play on several criteria.

For example, to forbid to visualize a directory files which hasn't got any index (e.g.: .html, .php), add the code:.

Protection by provenance
Authorize only two IP to read the directory:

whitelist with allow (obsolete in Apache 2.4)
If the authorization ranges have some addresses in common with the prohibited ranges, it's better to specify their precedence (the lines order in the .htaccess file doesn't change anything):
 * begin by the authorizations and then start the interdictions, by risking to ban what was previously allowed.
 * begin by the authorizations and then start the interdictions, by risking to ban what was previously allowed.


 * the contrary is less restrictive.
 * the contrary is less restrictive.

Authentication configuration
It's imperative to allow the authentication parameters modifications in the Apache settings.

The directive AllowOverride of a parent directory must contain the option.

The directives to place in the  are:
 * : authentication type communally adopted but poorly secured.
 * : the text as an invite in the dialog box.
 * : the passwords file path.
 * : specifies that a valid account is needed to accede to the folder.

We can also use  to authorize only the two accounts toto & sasa.

The authentication type basic uses not crypted passwords.

Some other more secured types exist, like digest, which is recommended to combine with HTTPS.

The first request is addressed to the protected directory and provokes the displaying of the dialog box, from which the user should identify (with login and password):
 * If the password is invalid, the dialog will be displayed again.
 * If it's valid, the navigator can record it, and never ask it again until the next relaunching.

Passwords file
The following command creates a passwords file called with one user toto: htpasswd -c /home/user/www/.htpasswd toto

To add or modify a user: htpasswd /home/user/www/.htpasswd sasa

Then, tell to .htaccess the .htpasswd path with: