Apache2 mod_substitute not working in <Location>

I have a working Reverse Proxy that is active only on a specific Location in my site, in this case for example: www.example.com/reverseproxy/site1 I am reverse proxying site1. I want to replace some part of the body of every page that is proxied so I tried to use mod_substitute, the problem is that I can't get it to work under <Location /reverseproxy>

This is my httpd (SSL is enabled):

<VirtualHost _default_:443> 

    ProxyPassInterpolateEnv On
    RewriteEngine On

    ... Some rewrite rules
    RewriteRule /?reverseproxy/http(s*):/([^\/]*)/*(.*) "http$1://$2/$3" [P]
    SSLProxyEngine On
    ProxyPassReverse "/reverseproxy/http${ssl}://${page}" http${ssl}://${page} interpolate

    SetOutputFilter INFLATE;proxy-html;SUBSTITUTE;DEFLATE;
    ProxyHTMLInterp On
    ProxyHTMLExtended Off

    ...Some ProxyURLMap
    AddOutputFilterByType SUBSTITUTE text/html
    Substitute "s|<body>|<body1>|"
</VirtualHost>

This substitute does work but it applies to all the pages and not only to /reverseproxy. When I try to put it in <Location /reverseproxy> it does not work, it just ignores it:

<Location /reverseproxy>
AddOutputFilterByType SUBSTITUTE text/html
Substitute "s|<body>|<body1>|"
</Location>

What I tried:

I tried adding

 RequestHeader unset Accept-Encoding

outside the <Location> tag but it didn't work

I tried then adding this

SetOutputFilter SUBSTITUTE;DEFLATE

in the <Location /reverseproxy> tag but no luck

And as someone suggested tried with this filterchain

FilterDeclare filter
FilterProvider filter SUBSTITUTE "%{CONTENT_TYPE} =~ m|^text/html|"
FilterDeclare unpackGZIP
FilterProvider unpackGZIP INFLATE "resp('Content-Encoding') == 'gzip'"

<Location /reverseproxy>
FilterChain unpackGZIP filter DEFLATE

Everything else inside the Location works, it just seems to ignore the substitution.


Solution 1:

I'm glad to say that there is a way to get around the interpolation issue, at least with the substitution issue.

Lots of google results for interpolation with mod_substitute come here, so I figured I'd help. It is indeed possible to do something like this:

## These modules are required
LoadModule filter_module modules/mod_filter.so
LoadModule substitute_module modules/mod_substitute.so
LoadModule env_module modules/mod_env.so

## Must be done in vhost directive
<VirtualHost:*:80>
PassEnv HOSTNAME_ENV_VARIABLE_NAME
Define SUBSTITUTE_STRING "s|http://hardcoded-url|http://${HOSTNAME_ENV_VARIABLE_NAME}|i"

<Location /my-path-here-wut-wut/>
        AddOutputFilterByType SUBSTITUTE my/mime-type-here
        Substitute "${SUBSTITUTE_STRING}"
</Location>


</VirtualHost>

When visiting /my-path-here-wut-wut/ which returns HTML containing http://hardcoded-url it will be substituted to http://<HOSTNAME_ENV_VARIABLE_NAME>