I'm trying to configure my server to automatically insert a tracking code (Piwik) to all pages served. I'm using both static sites and some PHP sites. I've used the following method found on Piwik forums, which is based on mod_filter and replacements.
AddOutputFilterByType SUBSTITUTE text/html application/x-httpd-php
Substitute "s~</body>~...PIWIK CODE...</body>~ni"
However, it only works for plain HTML pages. I've tried various MIMEs for PHP, like text/php or application/x-httpd-php5, but no avail. The PHP page never gets modified by the filter, while there are no problems with HTML page.
I'm starting to think that perhaps mod_php is somehow by-passing mod_filter replacements?
The problem was that gzip was enabled. For some strange reason, it only applied to sites processed through mod_php and not those served directly. I solved it by turning off gzip:
It works as a workaround, however, gzip is useful so I would like to see another solutition without turning off gzip.