【问题标题】:Apache: How to perform a conditional require based on server (.htaccess)?Apache:如何基于服务器(.htaccess)执行条件要求?
【发布时间】:2011-10-08 17:55:43
【问题描述】:

我的 Apache 生锈了。

如果两个服务器 foo 和 bar 使用相同的 .htaccess 文件,该文件限制用户使用 require group 或 require user,你如何根据服务器的要求?我不认为你在这里使用 RewriteCond,但我忘记了。


寻找类似的东西:

# if foo.com
require group foo 

# if bar.com
require group bar

【问题讨论】:

  • 这可能会有所帮助:stackoverflow.com/questions/736524/…
  • 是的,在我发布之前我已经看到了。它使用了 RewriteCond 和 RewriteRule,我想我已经用 I don't think you use RewriteCond here 覆盖了它们。我认为重写的处理方式与身份验证/权限控制不同。
  • 有一个allow from <host> 和deny from <host>,但是我没有看到像require group <groupname> from <host> 这样的东西
  • 嗯,.htaccess 和 httpd.conf 都包含 Apache 用来处理重写和权限控制的指令。当然可以在 httpd.conf 级别配置服务器 foo 和 bar 以使用不同的文件来控制目录级别的访问(例如 .htaccess_foo 和 .htaccess_bar ),但您的问题是关于为两者使用相同的 .htaccess 文件。我会看看我是否可以生成(或找到)一个示例。
  • @Peter:你说得对,此外,我会避免修改 httpd.conf 和/或重新启动 apache。这个问题的核心是服务器之间的组不一样。而不是foo 和bar,最好在所有服务器上将该组称为一个通用名称,但是,在实践中,理想主义处于次要地位。我也会深入研究它,谢谢帮助

标签: apache .htaccess conditional require


【解决方案1】:

正如这里评论:http://www.gossamer-threads.com/lists/modperl/modperl/93036,我只能找到一个 Mod_Perl 替代品,但我不想依赖它,如果将来关闭 mod_perl:

BEGIN 
{ 
    if (exists $ENV{MOD_PERL}) 
    { 
        require Apache::Constants; 
        import Apache::Constants qw(:common :http); 
    } 
} 

【讨论】:

    猜你喜欢
    • 2015-08-04
    • 1970-01-01
    • 2011-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-15
    • 1970-01-01
    • 2011-07-09
    相关资源
    最近更新 更多