Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 从子文件夹中删除.htpasswd保护_Apache_.htaccess_.htpasswd - Fatal编程技术网

Apache 从子文件夹中删除.htpasswd保护

Apache 从子文件夹中删除.htpasswd保护,apache,.htaccess,.htpasswd,Apache,.htaccess,.htpasswd,我已使用.htpasswd保护我的根文件夹 AuthType Basic AuthName "Restricted Access" AuthUserFile /home/a1199104/public_html/.htpasswd Require user lamak 上面的代码拒绝访问我的整个网站/文件夹/子文件夹,我有一个子文件夹public它有一些公共文件。我希望任何人都可以在没有密码保护的情况下访问此文件夹和文件,这是可能的吗?创建一个名为public/.htaccess的文件并放置此

我已使用.htpasswd保护我的根文件夹

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

上面的代码拒绝访问我的整个网站/文件夹/子文件夹,我有一个子文件夹public它有一些公共文件。我希望任何人都可以在没有密码保护的情况下访问此文件夹和文件,这是可能的吗?

创建一个名为
public/.htaccess
的文件并放置此代码:

Order allow,deny
allow from all
Satisfy any

您可以使用SetEnv和Order指令删除密码保护:

尝试:


感谢starkeen,它可以运行example.com/public/anyfile.php,但是当我转到example.com/public时,它问我为什么要登录?这是因为我们的setenif指令仅在匹配以/public和a/开头的请求uri字符串时才设置env变量noauth。它无法将uri字符串与/public匹配。您可以从setenif模式^/public/中删除尾随/来解决它。
#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