For work I was migrating an old undocumented reverse proxy configuration from 2.0 to 2.2. It contained some old perl scripts nobody understood and some strange bits here an there.

Long story short I started from scratch. I ran into the usual problems like redirects and hyperlinks being broken if they use full self referencing URL’s.

As it happened one of the perl scripts was there to fix those, it was ugly, unreadable and not very efficient.

Ofcourse I first had to deal with the redirects not working, this is easily fixed using ProxyPassReverse

ProxyRequests off
ProxyPass               /       http://jms1:7801/
ProxyPassReverse        /       http://jms1:7801/

I would have liked to have used a Location container but it was not allowed too.

This however still leaves urls inside the html, css and javascript files.
My original attempt was to do this using mod_proxy_html which worked fine, however due to it slightly reformatting it broke the 3 out of the 4 applications. I have no control over them so I had to scrap that idea.

Not wanting to go the perl route again I remembered playing with mod_substitute. After some initial issues I got it working fine. It is a bit more aggressive than mod_proxy_html but it is acceptable.

FilterDeclare DN_REPLACE_URLS
FilterProvider DN_REPLACE_URLS SUBSTITUTE resp=Content-Type $text/
FilterProvider DN_REPLACE_URLS SUBSTITUTE resp=Content-Type $/xml
FilterProvider DN_REPLACE_URLS SUBSTITUTE resp=Content-Type $/json
FilterProvider DN_REPLACE_URLS SUBSTITUTE resp=Content-Type $/javascript
FilterChain DN_REPLACE_URLS

Substitute "s|http://jms1:7801/|/|in"

Hopefully this is useful for somebody else too.