AEM: debugging Apache rewrite rules on dispatcher

2021-01-04

On my current project we have many Apache rewrites rules configured. I recently discovered an issue in one of our rules that caused our product pages not to render correctly. It can be quite cumbersome to check each single rule, I went looking for a better solution and found one: mod_rewrite logging using the LogLevel directive.

Within your <VirtualHost> directive

1
LogLevel alert rewrite:trace3

mod_rewrite offers detailed logging of its actions at the trace1 to trace8 log levels. The log level can be set specifically for mod_rewrite using the LogLevel directive: Up to level debug, no actions are logged, while trace8 means that practically all actions are logged. Using a high trace log level for mod_rewrite will slow down your Apache HTTP Server dramatically! Use a log level higher than trace2 only for debugging!

- http://httpd.apache.org/docs/current/mod/mod_rewrite.html#logging

1
tail -f error_log | fgrep '[rewrite:'

Can for example result in the following:

1
2
[rewrite:trace3] mod_rewrite.c(470): applying pattern '^/nl-be/products/([0-9]+)(/.+)?' to uri '/nl-be/products/1234.html'
[rewrite:trace2] mod_rewrite.c(470): rewrite '/nl-be/products/1234.html' -> '/content/company/be/nl.pdp.1234'

If you have any questions, do not hesitate to contact me or leave a comment below.

Created by Jeroen Druwé