Apache – Tips and Tricks

Things to know about Apache.
created by on 2013-01-08

Enable basic authentication for a website using the apache’s .htaccess file

Enable basic authentication in the .htaccess file:

AuthType basic
AuthName "Some Name"
AuthUserFile /var/www/.htpasswd
Require valid-user

Create a password file:

# Create a file to store the users and their passwords
touch /var/www/.htpasswd

# Add a user named "user1" to the htpasswd file
htpasswd /var/www/.htpasswd user1


Disbale Directory Listing with .htaccess

Put this in your .htaccess file:

# Disbale directory listing
Options -Indexes

- Apache.org: Indexes
- stackoverflow.com: deny directory listing with htaccess

Fork allmark on GitHub