在apache中使用基于位置的ACL的mo​​d_rewrite?

时间:2010-02-25 11:09:26

标签: authentication mod-rewrite apache2 cgi acl

有一个CGI脚本为我们的客户提供了一些API。调用语法为:

script.cgi?module=<str>&func=<str>[&other-options]

任务是为不同的模块制定不同的认证规则。

可选地,拥有不错的网址会非常棒。

我的配置:

<VirtualHost *:80>
    DocumentRoot /var/www/example
    ServerName example.com

    # Global policy is to deny all
    <Location />
            Order deny,allow
            Deny from all
    </Location>


    # doesn't work :(
    <Location /api/foo>
            Order deny,allow
            Deny from all
            Allow from 127.0.0.1
    </Location>


    RewriteEngine On

    # The only allowed type of requests:
    RewriteRule /api/(.+?)/(.+) /cgi-bin/api.cgi?module=$1&func=$2 [PT]

    # All others are forbidden:
    RewriteRule /(.*) - [F]

    RewriteLog /var/log/apache2/rewrite.log
    RewriteLogLevel 5

    ScriptAlias /cgi-bin /var/www/example

    <Directory /var/www/example>
            Options -Indexes
            AddHandler cgi-script .cgi
    </Directory>

 </VirtualHost>

嗯,我知道问题是处理指令的顺序。 mod_rewrite完成工作后将处理<Location>个问题。但我相信有一种方法可以改变它。 :)

最好使用标准Order deny,allow + Allow from <something>指令,因为它常用于其他类似的地方。

感谢您的关注。 :)

0 个答案:

没有答案