protecting directories using htaccess

Discussions about Apache mod Rewrite, .htaccess, Use, experiences ... URL Rewriting.

Moderator: Moderators

protecting directories using htaccess

Postby winsonlee » Wed May 09, 2007 1:30 pm

Under a root directory, I have 7 sub directories.
how can I create a htaccess to protect my root directory and another 3 subdirectories ?

another 4 more i would want it to remain as public.
winsonlee
 
Posts: 1
Joined: Wed May 09, 2007 1:26 pm

Advertisement

Postby dcz » Thu May 10, 2007 9:07 am

And welcome :D

Well, to protect a folder, you can use .htaccess (AuthUserFile) and .htpasswd, and you can reuse the same .htpasswd for several .htaccess.

The .htaccess should mention the path to the .htpasswd as well a few options such as :

Code: Select all
AuthUserFile /home/full/absolute/path/to/the/.htpasswd
AuthGroupFile /dev/null
AuthName "the name of the authorisation you want"
AuthType Basic
<Limit GET POST>
require valid-user
</Limit>


You can use the exact same .htaccess in as many folder as you like, they all be linked to the same .htapasswd. The .htpasswd should be composed of a list of users with encrypted passwords, something like :

Code: Select all
user1:jfGRQGRGsdfgd
user2:piofjzefefzeqFDd


The encryption used usually is md5(), but, depending on the type of install, on shared hosting mostly, it is possible that you'd need to add a key (could be composed of 2 letters) in the password prior to md5() it. This is to be checked from your host.

Then, if protecting several folder is not a problem, it's a bit more tricky if you want to protect the root level and not all of the sub folder. I actually never dealt with such settings.

What occurs is all sub folder of a protected folder should as well be protected.
But, you should be able to override the authorisation if you add a new auth .htaccess in the sub folder needing another auth, and add something like :
Code: Select all
Satisfy any
Order Deny,Allow
Allow from all


In the sub folder's .htaccess you want to stay public.

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21238
Joined: Fri Apr 28, 2006 9:03 pm


Return to Apache mod Rewrite

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: Bing [Bot] and 4 guests