排除 htaccess 保护目录中的一个文件夹 [英] Exclude one folder in htaccess protected directory

查看:24
本文介绍了排除 htaccess 保护目录中的一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个受 htaccess 保护的目录.这是我现在使用的代码:

I have a directory protected by htaccess. Here is the code I use now:

AuthName "Test Area"
Require valid-user
AuthUserFile "/***/.htpasswd"
AuthType basic

这工作正常.但是,我现在在这个文件夹中有一个目录,我想允许任何人访问它,但不知道该怎么做.

This is working fine. However, I now have a directory inside of this folder that I would like to allow anyone to access, but am not sure how to do it.

我知道可以将文件移到受保护目录之外,但长话短说,文件夹需要留在受保护文件夹内,但所有人都可以访问.

I know that it is possible to just move the files outside of the protected directory, but to make a long story short the folder needs to stay inside the protected folder, but be accessible to all.

如何限制对文件夹的访问,但允许对子文件夹的访问?

How can I restrict access to the folder, but allow access to the subfolder?

推荐答案

根据 这篇文章 你可以通过使用 SetEnvIf 来实现.您匹配要访问的每个文件夹和文件,并为它们定义一个环境变量允许".然后添加一个条件,如果此环境变量存在,则允许访问.

According to this article you can accomplish this by using SetEnvIf. You match each of the folders and files you want to grand access to and define an environment variable 'allow' for them. Then you add a condition that allows access if this environment variable is present.

您需要将以下指令添加到您的 .htaccess 中.

You need to add the following directives to your .htaccess.

SetEnvIf Request_URI "(path/to/directory/)$" allow
SetEnvIf Request_URI "(path/to/file\.php)$"  allow
Order allow,deny
Allow from env=allow
Satisfy any

这篇关于排除 htaccess 保护目录中的一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆