Redirect all requests (including POST) from one Apache server to another

In order to test POST callbacks made by a payment gateway without having to work via FTP on a publicly-accessible server, I needed a simple solution to redirect all requests from said server to my workstation, that is on the same network as the server, but is not accessible from outside.

The easiest thing to do was to use the mod_rewritemod_proxy and mod_proxy_http Apache modules. You can easily activate all of them in Ubuntu with:

1
sudo a2enmod rewrite proxy proxy_http

I created an empty folder on the server and placed a .htaccess file with the following lines in it:

1
2
RewriteEngine On
RewriteRule ^(.*)$ http://10.4.2.155/$1 [NC,P]

The [P] at the end of the RewriteRule specifies that the request should be handled by the proxy module so all GET and POST data are preserved. Therefore, all requests made in that directory will be automatically forwarded to my machine.