Wednesday, May 5, 2010

.htaccess

Put the following in the .htaccess file which should be in the top directory you want to restrict access to.

AuthUserFile /server/path/to/.htpasswd
AuthName "Login and Password Required"
AuthType Basic
 
require valid-user


You then have to create the .htpasswd file:
htpasswd -c /path/to/where/you/want/it/.htpasswd username

This will then prompt you to set the password for that username as a part of the file creation.

Best to have it a level above where the .htaccess file is for security reasons and make sure that the permissions are 644.

chmod 644 filename


In the httpd.conf - in apache2 probably /etc/apache2/sites-enabled/000-default - within the tags change AllowOverride None to AllowOverride ALL.


If you get a message "Invalid command 'RewriteEngine', perhaps mis-spelled or defined by a module not included in the server configuration" then run the following command:


sudo a2enmod rewrite

No comments: