0

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.?

user4795555
  • 13
  • 1
  • 3

2 Answers2

0

Create a file called public/.htaccess and place this code:

Order allow,deny
allow from all
Satisfy any
anubhava
  • 761,203
  • 64
  • 569
  • 643
0

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
Amit Verma
  • 40,709
  • 21
  • 93
  • 115
  • 1
    Thanks starkeen it works example.com/public/anyfile.php, but when i go to example.com/public without a slash in end ,it asked me for login why? – user4795555 Nov 23 '15 at 06:16
  • That is because our SetEnvIf directive sets the env variable **noauth** only when it matchs the request uri string starting with **/public** and a **/** . it fails to match uri string with **/public** . you can remove the trailing **/** from setenvIf pattern **^/public/** to solve it. – Amit Verma Nov 23 '15 at 08:13