Replacing hyperlinks in Apache2 ProxyPass

Posted by Jeroen on Server Fault See other posts from Server Fault or by Jeroen
Published on 2012-08-27T21:23:04Z Indexed on 2012/08/27 21:41 UTC
Read the original article Hit count: 365

Filed under:
|

I am using Apache2 with mod proxy on Ubuntu 12.04 as a reverse proxy to some back-end server:

<VirtualHost *:80>
  ProxyPass / http://somewhere.com/mysite
  ProxyPassReverse / http://somewhere.com/mysite
  ServerName www.mysite.nl
  ServerAlias mysite.nl *.mysite.nl
</VirtualHost>

However, unfortunately the back-end server has some internal links hardcoded; e.g. a link to somewhere else in the site has <a href="http://somewhere.com/mysite/something"> instead of just <a href="something.png">. Is there a way I can use Apache to replace strings in the body as served by the backend before passing it back to the client? E.g replace all instances of "http://somewhere.com/site/" with "http://mysite.nl/" ?

I know nginx or so is better as a reverse proxy, but the server is hosting other stuff so port 80 needs to be Apache2.

© Server Fault or respective owner

Related posts about apache2

Related posts about reverse-proxy