GadElKareem

Replacing URLs in HTML and JS with mod_proxy on apache 2.2

Simple way to replace URLs for proxied websites using mod filter and substitute

<VirtualHost *:80 >
ProxyPreserveHost On
ServerName proxy-test.example.com
FilterDeclare MYFILTER
FilterProvider MYFILTER SUBSTITUTE resp=Content-Type $text/
FilterProvider MYFILTER SUBSTITUTE resp=Content-Type $/xml
FilterProvider MYFILTER SUBSTITUTE resp=Content-Type $/json
FilterProvider MYFILTER SUBSTITUTE resp=Content-Type $/javascript
<Location />
#disable gzip
RequestHeader unset Accept-Encoding
FilterChain MYFILTER
Substitute "s!(images|static|test).example.com!proxy-$1.example.com!i"
</Location>
ProxyPass / http://test.example.com/
ProxyPassReverse / http://test.example.com/
</VirtualHost >
Modify on Gist