Protect directory with .htaccess with Drupal installed

Posted on October 12, 2012

0


Want to use .htaccess to authorize your content, under a directory that has Drupal installed? Getting Page not found errors? Just add ErrorDocument 401 “Unauthorized” on your .htaccess file which you are trying to use for protection.

Example: domain.fi has Drupal 7 installed. I want to put some big files for distribution on domain.fi/upload. Customer wants to restrict access on those files for press only, so lets protect them with Apaches .htaccess.

I create /upload directory and in that directory I’m saving .htaccess with these lines:

ErrorDocument 401 “Unauthorized”
AuthUserFile /home/username/.htpasswd
AuthName “Identifying message”
AuthType Basic
require valid-user
Options +Indexes

On command line, change to directory /home/username/ and type:

htpasswd -c .htpasswd press

Enter password and save. Test with browser, when trying to open domain.fi/upload you should be prompted for username and password. If you get Page not found, you either forgot to put ErrorDocument in your .htaccess or AuthUserFile line is pointing to a non-existing file.

Advertisements