gpt4 book ai didi

apache - .htaccess : understanding use of deny, 允许和允许、拒绝

转载 作者:行者123 更新时间:2023-12-01 19:05:10 25 4
gpt4 key购买 nike

我试图通过一个简短的测试示例来了解 order Deny,allow 语句如何根据我到目前为止所读到的内容使用react。

我有以下站点结构用于测试:

/index.htm
/.htaccess (1)
/子文件夹/index.htm
/子文件夹/.htaccess (2)

.htaccess (1)

order deny,allow  
allow from all

子文件夹/.htaccess (2)

order deny,allow  
deny from all

无论我在 2 个 .htaccess 文件中使用允许、拒绝/拒绝、允许(以及所有 4 种可能的组合)的顺序,都不允许我访问子文件夹/index.htm。

据我所知,至少有一种组合,根允许所有在子文件夹拒绝所有上获胜,所以我不理解为什么我无法在如此简单的示例中成功做到这一点。

您能解释一下发生的原因和情况吗?

最佳答案

订单指令

规则order deny,alloworder allow,deny定义 deny from 的顺序和allow from指令已处理。所有允许和拒绝规则都会被处理,最终的相关规则将覆盖任何先前的规则。请参阅Order Directive mod_authz_host 模块文档部分进行确认。

Note that all Allow and Deny directives are processed, unlike a typical firewall, where only the first match is used. The last match is effective (also unlike a typical firewall). Additionally, the order in which lines appear in the configuration files is not significant -- all Allow lines are processed as one group, all Deny lines are considered as another, and the default state is considered by itself.

例如,如果我们在允许规则之前处理拒绝规则,我们可以有效地创建允许的 IP 地址白名单。

order deny,allow
deny from all
allow from 127.0.0.1

相反,在下面的示例中,我们在拒绝规则之前处理允许规则,以获得被拒绝的 IP 地址的黑名单。

order allow,deny
allow from all
deny from 127.0.0.1


继承

子目录将继承父目录的规则,除非它们声明自己的规则。如果子目录使用 order 指令或允许/拒绝指令,则不会继承父目录的规则。请参阅Bug 52406指的是 Merging of configuration sections本文档的部分,用于确认此行为。

For modules that don't implement any merging logic, such as mod_access_compat, the behavior in later sections depends on whether the later section has any directives from the module. The configuration is inherited until a change is made, at which point the configuration is replaced and not merged.

简单测试

您还可以进行这个简单的测试来确认此行为。

将以下行放入父目录 .htaccess .

order deny,allow  
deny from all

以及子目录 .htaccess 中以下任何或所有行.

order deny,allow  
deny from 0.0.0.0

您将看到子目录现在可以公开访问,即使父目录包含 deny from all并且子目录没有 allow from指令。


结论

根据文档和实验,父目录似乎不可能以任何方式覆盖子目录的指令。

关于apache - .htaccess : understanding use of deny, 允许和允许、拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24728814/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com