apache mod_substitute works in curl but not on browser

To troubleshoot such issues, it is a good idea to compare the headers in the browser with the ones in curl (-i, --include flag will show headers, and -H flag can add them), and from the browser add one at a time to curl command until the problem reproduces.

I read in the comments section of mod_substitute docs page that describes symptoms like the ones you described, with mod_substitute sometimes not working as expected:

It turned out it was the order of our filter chain. DEFLATE was running before SUBSTITUTE. For small files, DEFLATE was not doing anything, so it worked. On some internal proxy stuff that did not send an Accept-Encoding header it was working. But, other times it did not. In the end, this worked best:

AddOutputFilterByType INFLATE;SUBSTITUTE;DEFLATE text/html text/plain text/xml

Another option is to unset Accept-Encoding header for the target resource where mod_substitute is supposed to do it's substitutions.

RequestHeader unset Accept-Encoding

It's (arguably) better to use the other trick instead, so that you can reap the benefits both of mod_deflate and mod_substitute though.


Disabling gzip compression solves the issue. Add the below lines to httpd.conf SetEnv no-gzip 1 solves the problem