Search code examples
apache.htaccess.htpasswd

Remove .htpasswd protection from a subfolder


I have protected my root folder using .htpasswd

AuthType Basic
AuthName "Restricted Access"
AuthUserFile /home/a1199104/public_html/.htpasswd
Require user lamak

The above code deny access to my whole site/folder/subfolder, I have a subfolder public It has some public files .I want anyone to access this folder and files without password protection, is this possible.?


Solution

  • You can use SetEnv and Order directive to remove password protection :

    Try :

    #set env variable noauth if uri is "/public/files"
    SetEnvIf Request_URI ^/public/ noauth=1
    
    #auth
    AuthType Basic
    AuthName "Restricted Access"
    AuthUserFile /home/a1199104/public_html/.htpasswd
    Require user lamak
    
     #Here is where we allow/deny
    Order Deny,Allow
    Satisfy any
    Deny from all
    Require user lamak
    Allow from env=noauth