如何从子目录中删除 .htaccess 密码保护

发布于 2024-08-05 01:55:04 字数 394 浏览 8 评论 0原文

我使用 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

转瞬即逝 2024-08-12 01:55:04

您需要在所需目录中创建一个新的 .htaccess 文件,并在其中包含 Satisfy any 指令,如下所示,对于 Apache 2.3:

# allows any user to see this directory
Satisfy Any

Apache 2.4 中的语法已更改,这具有相同的效果:

Require all granted

You need to create a new .htaccess file in the required directory and include the Satisfy any directive in it like so, for up to Apache 2.3:

# allows any user to see this directory
Satisfy Any

The syntax changed in Apache 2.4, this has the same effect:

Require all granted
安稳善良 2024-08-12 01:55:04

添加到 RageZ 的答案中,我在服务器指令中使用了它:

<Directory /var/www/protected/>
     AuthType Basic
     AuthName "Production"
     AuthUserFile /path/to/.htpasswd
     Require valid-user
</Directory>

<Directory /var/www/protected/unprotected>
     Satisfy Any
</Directory>

太棒了。谢谢愤怒Z!

Adding to RageZ's answer, I used this in the Server Directives:

<Directory /var/www/protected/>
     AuthType Basic
     AuthName "Production"
     AuthUserFile /path/to/.htpasswd
     Require valid-user
</Directory>

<Directory /var/www/protected/unprotected>
     Satisfy Any
</Directory>

Awesome. Thanks RageZ!

一萌ing 2024-08-12 01:55:04

只需使用以下指令在所需的子目录中创建一个新的 .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

拥抱影子 2024-08-12 01:55:04

以下是允许子目录“foo”通过站点上主 .htaccess 文件进行基本身份验证的方法:

AuthType Basic
AuthName "Password Required"
AuthUserFile /dir/.htpasswd
Require expr %{REQUEST_URI} =~ m#^/foo/#
Require valid-user

注意:这适用于 Apache 2.4。我还没有确认早期版本。

Here is a way to allow subdirectory "foo" through the basic authentication from the main .htaccess file on a site:

AuthType Basic
AuthName "Password Required"
AuthUserFile /dir/.htpasswd
Require expr %{REQUEST_URI} =~ m#^/foo/#
Require valid-user

Note: This works in Apache 2.4. I have not confirmed for earlier versions.

千鲤 2024-08-12 01:55:04

您需要将另一个 .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.

℉絮湮 2024-08-12 01:55:04

如果您想阻止 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文