8

I have an apache server that works as a reverse proxy in our DMZ. We have an external service that posts back to a particular URL on this server. There is a need now for this service to postback to an entirely new application, but this will most likely change again in the near future as we're in a testing phase right now.

So to resolve this, I'm trying to take the incoming postback request, /smsPostback.php, and rewrite it to a new relative URL, /SMSHandler/Process. This part is working.

However defined immediately below in the config, I have a ProxyPass directive to proxy all traffic to /SMSHandler to an internal server.

These are the new lines from the apache conf file:

RewriteRule ^/smsPostback.php$ /SMSHandler/Process 
##Proxy pass smshandler
ProxyPass /SMSHandler http://172.29.61.49:8080/SMSHandler
ProxyPassReverse /SMSHandler http://172.29.61.49:8080/SMSHandler

And these are the logs from the rewrite log:

172.29.61.49 - - [24/Jan/2012:18:43:36 --0500] [test.hidden.com/sid#5eace0][rid#446b770/initial] (2) init rewrite engine with requested uri /smsPostback.php
172.29.61.49 - - [24/Jan/2012:18:43:36 --0500] [test.hidden.com/sid#5eace0][rid#446b770/initial] (3) applying pattern '^/smsPostback.php$' to uri '/smsPostback.php'
172.29.61.49 - - [24/Jan/2012:18:43:36 --0500] [test.hidden.com/sid#5eace0][rid#446b770/initial] (2) rewrite '/smsPostback.php' -> '/SMSHandler/Process'
172.29.61.49 - - [24/Jan/2012:18:43:36 --0500] [test.hidden.com/sid#5eace0][rid#446b770/initial] (2) local path result: /SMSHandler/Process
172.29.61.49 - - [24/Jan/2012:18:43:36 --0500] [test.hidden.com/sid#5eace0][rid#446b770/initial] (2) prefixed with document_root to C:/hidden.com/SMSHandler/Process
172.29.61.49 - - [24/Jan/2012:18:43:36 --0500] [test.hidden.com/sid#5eace0][rid#446b770/initial] (1) go-ahead with C:/hidden.com/SMSHandler/Process [OK]

And this is the error log entry from apache:

[Tue Jan 24 18:43:36 2012] [error] [client 172.29.61.49] File does not exist: C:/fmfacilitymaintenance.com/SMSHandler

Any thoughts as to why it never reverse proxies the request, but rather tries (and fails) to serve it locally?? Thanks!

Matt
  • 1,300
  • 2
  • 14
  • 31

1 Answers1

21

You need to add a PT (PassThrough) to your RewriteRule so that apache takes the rewritten URI and passes it back through the URL handling pipeline (so that mod_proxy can handle it). The rule should look like this:

RewriteRule ^/smsPostback.php$ /SMSHandler/Process [L,PT]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • 5
    you can drop the `Last`, it's implied with Passthrough http://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_pt – oberhamsi Oct 29 '13 at 09:12
  • Is this possible if the rewrite rules are contained in an `.htaccess` file? It seems like my requests are being handled by the proxy first, and then the server that handles the proxied requests doesn't care about the `.htaccess` file. Unfortunately I need to keep the rules contained in that file for biz-rule reasons. – Adam Tuttle Nov 29 '19 at 17:58
  • @AdamTuttle with .htaccess, the matched path is considered relative to the current directory and it doesn't contain the leading "/". Therefore you cannot match on it. – nimai Jun 25 '20 at 15:54