http, https and htpasswd

projects
projects used Ask the Experts™
on
I want to use htaccess/htpasswd on only one directory and any sub-directories inside that one and on.

html
html/authpages/(bunch of additional directories)

I want to allow anyone to reach html but I only want to allow authenticated https connections into the authpages directory and all sub-directories.

I have been searching the net for the solution but so far, I can only put the htaccess file at the root of the web site and protect the entire site whereas I want to protect only certain subdirectories so thought I would need an htaccess file in which ever subdirs I would want to protect?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Fixer of Problems
Most Valuable Expert 2014
Commented:
No, you can put 'htaccess' in any directory you want on Apache.  What ever you put in it will affect that directory and all the ones below it.  Here is the general info from Apache: http://httpd.apache.org/docs/current/howto/htaccess.html   And this appears to be a good guide to using 'htaccess': http://www.htaccess-guide.com/

Author

Commented:
Don't really need a guide, I've been using it for a while now but putting my htaccess in the directory I want to protect, leaving the ones above it non protected is not working.

I have my .htpasswd file above html/
I have my .htaccess in the html/.htaccess

The above protects the entire site.

Now, I only want to protect
html/authpages/*

so I put my .htaccess file in there, still pointing to the same .htpasswd file and that doesn't seem to work.

Author

Commented:
Hang on... now it seems to be working... Let me do some testing.
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

Author

Commented:
Can I put different .htaccess files in different sub-directories also? Each could either point to the same .htpasswd file or to it's own .htpasswd if needed.

Author

Commented:
Yup, I can put .htaccess files pointing either to the same password file or a new one.

All good, thanks for the leads and tips.
Dave BaldwinFixer of Problems
Most Valuable Expert 2014

Commented:
You're welcome, glad to help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial