Computers Linux

Proxy a web site and change the content on the fly

Apache can do just about everything with a bit of configuration. I have used HTTP proxying on a number of occasions to make content from one site appear to come from another site. This can be very handy for sites I host at home where I only have one IP address but two servers and want to host different web sites on the same public IP – and all of them on the standard HTTP port.

However, until recently I hadn’t experienced that Apache can also rewrite the content in the actual response. I was faced with the requirement to change all the URIs in the proxied web site so that they pointed to the new URL. When I first searched the net I found the module mod_proxy_html which sounded like the way forward. In the end I didn’t go that route since I found it overly complex and didn’t transform all instances of the links. Instead, the solution was simple and used another Apache module – mod_substitute.

The following virtual host configuration sets up a proxy so that the site is proxied to In addition, any occurrences of is changed into

<VirtualHost *>
  <Proxy *>
    Order deny,allow
  ProxyRequests on
  ProxyPass /
  ProxyPassReverse /
  AddOutputFilterByType SUBSTITUTE text/html
  Substitute "s|||n"

One reply on “Proxy a web site and change the content on the fly”

When proxying with Apache, it is advisable to use the new version – Apache 2.2 because it’s much improved from the earlier 2.0 version. The new version supports load-balancing as a standard feature and I highly recommend upgrading to the 2.2 version.

Comments are closed.