HowTo: Protect URL with htpasswd file in Apache2 (Ubuntu)

Step 1: Install package: sudo aptitude install apache2-utils

Step 2: Create a htpasswd file and register users in it:
a) For first user – user1: htpasswd -c /home/faraz/.htpasswd user1
b) For second user – user2: htpasswd /home/faraz/.htpasswd user2

Step 3: Make the following entry in the /etc/apache2/apache2.conf
for the URL: http://myserver/index.php/en/downloads/category/my-files, the entry should be:

AllowOverride None
AuthType basic
AuthName “private”
AuthUserFile “/home/faraz/.htpasswd”
Require valid-user

Step 4: Restart apache: sudo service apache2 restart

Note: This will match the following URLs as well:
http://myserver/index.php/en/downloads/category/my-files?a=1
http://myserver/index.php/en/downloads/category/my-files?b=2&c=3

Advertisement

2 thoughts on “HowTo: Protect URL with htpasswd file in Apache2 (Ubuntu)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s