Blog tvlooy

Debugging rewrites on Apache 2.4

Apache 2.4, mod_rewrite, mod_alias | July 24, 2015

In Apache 2.4, the RewriteLog and RewriteLogLevel on mod_rewrite level are replaced by LogLevel on core level which you can configure for all modules. See the Apache documentation for detailed information:

Note that the Redirect directive is part mod_alias and not of mod_rewrite. So make sure you are looking for the right logging information. While mod_rewrite offers detailed logging of its actions at the trace1 to trace8 log levels, mod_alias unfortunately does not have this.

Enable logging for mod_rewrite and mod_alias:

LogLevel alert rewrite:trace3 alias:debug

Note that level trace4 also activates the logging of rewrite conditions.

mod_rewrite

For a redirect like this:

RewriteEngine On RewriteRule /foo /bar [R=301,L]

You will see logging information like this:

[Fri Jul 24 11:25:21.133477 2015] [rewrite:trace3] [pid 23422:tid 140451352831744] mod_rewrite.c(475): [client ?.?.?.?:53894] my.domain - admin [example.com/sid#7fbd695de898][rid#7fbd693d00a0/initial] [perdir /var/www/] add path info postfix: /var/www/bar -> /var/www/bar/ [Fri Jul 24 11:25:21.133558 2015] [rewrite:trace3] [pid 23422:tid 140451352831744] mod_rewrite.c(475): [client ?.?.?.?:53894] my.domain - admin [example.com/sid#7fbd695de898][rid#7fbd693d00a0/initial] [perdir /var/www/] strip per-dir prefix: /var/www/bar/ -> bar/ [Fri Jul 24 11:25:21.133569 2015] [rewrite:trace3] [pid 23422:tid 140451352831744] mod_rewrite.c(475): [client ?.?.?.?:53894] my.domain - admin [example.com/sid#7fbd695de898][rid#7fbd693d00a0/initial] [perdir /var/www/] applying pattern '/foo' to uri 'bar/' [Fri Jul 24 11:25:21.133576 2015] [rewrite:trace1] [pid 23422:tid 140451352831744] mod_rewrite.c(475): [client ?.?.?.?:53894] my.domain - admin example.com/sid#7fbd695de898][rid#7fbd693d00a0/initial] [perdir /var/www/] pass through /var/www/bar

mod_alias

If you try to do this with mod_alias, even if you enable logging at the highest level, you will see nothing in the logs. Only the usual debug info like for this rewrite:

Redirect 301 /foo /bar

You will see this information:

[Fri Jul 24 11:12:42.319023 2015] [alias:debug] [pid 19368:tid 140451394795264] mod_alias.c(500): [client ?.?.?.?:53731] AH00675: incomplete redirection target of '/bar/' for URI '/foo/' modified to 'http://example.com/bar/'

If the URL is corrected to the redirect below, you will see nothing in the logs. So, you will not be able to debug your redirects from mod_alias.

Redirect 301 /foo http://example.com/bar