3

I need to ensure my custom filter always executes before the mod_rewrite. As per Apache Tutor, filters do not run in a deterministic order:

The request processing axis is straightforward: the phases happen strictly in order. But confusion arises in the data axis. For maximum efficiency, this is pipelined, so the content generator and filters do not run in a deterministic order. So, for example, you cannot in general set something in an input filter and expect it to apply in the generator or output filters.

How to ensure execution sequence of two filters, or is it possible?


Update: Someone has indicated to mod_info to display detailed information about modules and their order.

4

1 回答 1

4

理解这一点的最好方法是查看 apache 源代码。ap_hook_fixups 的 mod_proxy 和 mod_rewrite 用法是如何在特定模块之前或之后插入挂钩的完美示例。

假设你想在 mod_rewrite 之前插入一个钩子,你可以这样做:

static int my_fixup(request_rec *r)
{
    /* do something with request headers before it goes to the mod_rewrite */
    return OK;
}

static void register_hooks(apr_pool_t *p) {
    static const char * const aszSucc[] = {"mod_rewrite.c", NULL};
    ap_hook_fixups(my_fixup, NULL, aszSucc, APR_HOOK_FIRST);
}

此外,您可以查看http://httpd.apache.org/docs/2.2/developer/hooks.html页面以了解其他类型的钩子,或者更好地了解如何控制钩子调用顺序。

于 2012-10-18T18:31:18.583 回答