How to use .htaccess on subfolders with Drupal

If you’re 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.

Did you like this post?

Subscribe To The RSS Feed!
To catch many more articles like this in the future, make it easy on yourself and subscribe to me via RSS. You will not regret it!

Do you have a question?
We will do our best to try and solve any building automation, protocol, integration problem you may have

2 Responses to “How to use .htaccess on subfolders with Drupal”


  1. 1 Alex Oct 30th, 2009 at 6:04 pm

    THANK YOU! Wow I’ve spent a couple frustrating days on this problem, and I am so glad I cam across this!

    Very nice clear post.

  2. 2 choopong Jan 10th, 2010 at 8:53 pm

    thank you so much :)