How to use .htaccess on subfolders with Drupal
If you are trying to password protect a subdirectory of your Drupal website using the traditional .htaccess and .htpassword method, you might be having trouble accessing the contents of the subdirectory. When trying to navigate to a page under the subfolder, Drupal simply displays it as not found.
There is a very easy fix for this. Simply add this line at the top of your .htaccess file:
ErrorDocument 401 Unauthorized
This must be done for every single subdirectory containing the .htaccess and .htpasswd files.
Your final .htaccess file would look something like this:
ErrorDocument 401 "Unauthorized" AuthUserFile /locationofyoursubdirectory/.htpasswd AuthGroupFile /dev/null AuthName "Secure Document" AuthType Basic require user user1 require user user2 require user user3 require user user4 require user user5
After inserting that small line at the top of your .htaccess file, your subdirectories should be password protected but accessible, like intended.
6 Comments on How to use .htaccess on subfolders with Drupal
6 Responses to How to use .htaccess on subfolders with Drupal
-
Alex says: October 30, 2009 at 6:04 pm
THANK YOU! Wow Ive spent a couple frustrating days on this problem, and I am so glad I came across this!
Very nice clear post.
Reply -
choopong says: January 10, 2010 at 8:53 pm
thank you so much :)
Reply -
Drupal Developers says: May 20, 2011 at 5:13 am
What to do in case of non www to www redirects when individual sub folders have their own .htaccess files? The global .htaccess changes are ignored because of the commented code in the folder level .htaccess. When we uncomment the code, it redirects to the www of the parent folder rather than the www of the same.
Reply - Ajgor says: June 26, 2011 at 5:54 am
ITS COOL
thank you so much :)
Reply - JonoB says: December 17, 2011 at 3:58 pm
Thank you sorted my problem out straight away!
Reply - Chris says: July 8, 2018 at 6:27 am
This was bugging me for YEARS!
Thank you so much!
Reply