如何从子目录中删除 .htaccess 密码保护
我使用 .htaccess
对整个网站进行了密码保护,但我想公开其中一个子目录,以便无需密码即可查看。
如何禁用子目录的 htaccess 密码保护?具体来说,.htaccess
语法是什么。
这是我的 .htaccess
文件,它位于我的 ftp 根目录中。
AuthName "Site Administratrion" AuthUserFile /dir/.htpasswd AuthGroupFile /dev/null AuthName secure AuthType Basic require user username1 order allow,deny allow from all
I have password protected my entire website using .htaccess
but I would like to expose one of the sub directories so that it can be viewed without a password.
How can I disable htaccess password protection for a sub directory? Specifically what is the .htaccess
syntax.
Here is my .htaccess
file that is placed in the root of my ftp.
AuthName "Site Administratrion" AuthUserFile /dir/.htpasswd AuthGroupFile /dev/null AuthName secure AuthType Basic require user username1 order allow,deny allow from all
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您需要在所需目录中创建一个新的
.htaccess
文件,并在其中包含Satisfy any
指令,如下所示,对于 Apache 2.3:Apache 2.4 中的语法已更改,这具有相同的效果:
You need to create a new
.htaccess
file in the required directory and include theSatisfy any
directive in it like so, for up to Apache 2.3:The syntax changed in Apache 2.4, this has the same effect:
添加到 RageZ 的答案中,我在服务器指令中使用了它:
太棒了。谢谢愤怒Z!
Adding to RageZ's answer, I used this in the Server Directives:
Awesome. Thanks RageZ!
只需使用以下指令在所需的子目录中创建一个新的
.htaccess
:Allow from all
您可以仅使用以下指令限制您的 IP:
Allow from xxxx
请参阅:http://httpd.apache.org/docs/current/mod/mod_access_compat .html
Simply create a new
.htaccess
in the desired subdirectory with this directive:Allow from all
You can restrict to your IP only with :
Allow from x.x.x.x
See : http://httpd.apache.org/docs/current/mod/mod_access_compat.html
以下是允许子目录“foo”通过站点上主 .htaccess 文件进行基本身份验证的方法:
注意:这适用于 Apache 2.4。我还没有确认早期版本。
Here is a way to allow subdirectory "foo" through the basic authentication from the main .htaccess file on a site:
Note: This works in Apache 2.4. I have not confirmed for earlier versions.
您需要将另一个 .htaccess 文件添加到覆盖身份验证的子目录。 .htaccess 向上级联,即它将在当前文件夹中查找,然后向上一级依此类推。
You need to add another .htaccess file to the subdirectory that overrides the authentication. .htaccess cascades upwards, i.e. it will look in the current folder, then go up a level and so on.
如果您想阻止 htaccess 身份验证中的任何特定目录,那么您可以在 htaccess 文件顶部使用以下代码。
AuthType 基本
AuthName“输入密码”
AuthUserFile /home/public_html/.htpasswd /*.htpasswd 文件的路径*/
需要有效用户
SetEnvIf Request_URI "(/DIRECTORY_NAME/)$" 允许
订单允许、拒绝
允许来自 env=allow
另外如果你想阻止多个目录那么
添加
SetEnvIf Request_URI "(/DIRECTORY_NAME/)$" 允许
与您想要从 htaccess 防护中删除的目录一样多的次数。
If you want to prevent any specific directoty from htaccess authentication then you can use following code in your htaccess file at top.
AuthType Basic
AuthName "Enter Pass"
AuthUserFile /home/public_html/.htpasswd /*PATH TO YOUR .htpasswd FILE*/
Require valid-user
SetEnvIf Request_URI "(/DIRECTORY_NAME/)$" allow
Order allow,deny
Allow from env=allow
Also If you want to prevent multiple directories then
add
SetEnvIf Request_URI "(/DIRECTORY_NAME/)$" allow
as many time as many directories, you want to remove from htaccess prevention.