I built a reverse proxy with Apache 2.4 on a cento's 7 server. It works with standard html pages but i need to substitute some url stored in .js files too. The directive:
ProxyHTMLExtended On
should enable the parsing inside external .css and .js files but it doesn't work. In the log file I can see:
[proxy_html:trace1] [pid 3263] mod_proxy_html.c(823): [client xxx] Non-HTML content; not inserting proxy-html filter
I tried to use mod_substitute, this is the interesting part in my httpd.conf:
ProxyPass /mylocation/ http://remoteserver/
<Location /mylocation/>
ProxyHTMLEnable On
ProxyHTMLExtended On
LogLevel debug proxy_html:trace3 substitute_module:debug
RequestHeader unset Accept-Encoding
AddOutputFilterByType SUBSTITUTE text/javascript text/html
Substitute "s|/css/|/mylocation/css/|ni"
Substitute "s|/js/|/mylocation/js/|ni"
Substitute "s|/custom_logo/|/mylocation/custom_logo/|ni"
Substitute "s|/html/|/mylocation/html/|ni"
Substitute "s|/current_config/|/mylocation/current_config/|ni"
Substitute "s|/web_lang/|/mylocation/web_lang/|ni"
Substitute "s|/custom_lang/|/mylocation/custom_lang/|ni"
ProxyPassReverse /
ProxyHTMLURLMap //remoteserver /mylocation/
ProxyHTMLURLMap http://remoteserver /mylocation/
ProxyHTMLURLMap /mylocation /mylocation
ProxyHTMLURLMap ^\/(.*) /mylocation/$1 R
</Location>
But in the log file there aren't any mod_substitute trace. It seems mod_substitute is never called.
The proxyHTMLURLMap rules works fine, but only on regular html files.
Depending on the .js file I'm asking to the server, I can see in the log file:
[xml2enc:debug] [pid 3259] mod_xml2enc.c(254): [client xxx] AH01434: Charset ISO-8859-1 not supported by libxml2; trying apr_xlate
or
[proxy_html:trace1] [pid 3263] mod_proxy_html.c(823): [client xxx] Non-HTML content; not inserting proxy-html filter
then the process stop, I receive the file but nothing has been replaced on it.
1) Wy the "ProxyHTMLExtended On" rule don't parse external .js files as described in Apache documentation?
2) Wy the mod_substitute don't work?
I'll try to answer to your questions
You say that
ProxyHTMLExtendedDirective:That's seems to be incorrect, the current doc says:
That means that embedded scripts, the ones in
<script></script>are checked. It doesn't mention .js files.About this i don't know for sure why it doesn't work, but assuming the mod_substitute is enabled since apache started without error, the only thing that I can guess is that apache is sending
application/javascriptas Mime-Type instead oftext/javascriptthat you wroteSome bonus suggestions:
ProxyHTMLURLMap ^\/(.*) /mylocation/$1 RwithProxyHTMLExtended Onbecause will translate every/in your scripts, if you have<script> var a = 12/2; </script>will be translated into<script> var a = 12/mylocation/2; </script>. I would consider usingProxyHTMLURLMap / /mylocation/ c(thecflag means: "Pass embedded script and style sections through untouched.")ProxyHTMLURLMap /mylocation /mylocationProxyHTMLURLMap http://remoteserver /mylocation/will add an extra/to your urls, it still works but, imho, it is not a good translation.Ex.
<a href="http://remoteserver/about">becomes<a href="/mylocation//about">I suggest to rewrite it like this
ProxyHTMLURLMap http://remoteserver /mylocation