0

I need to configure proxy with apache to proxy requests like

http://example.com/proxy/www.anothersite.com/[some-params]

to

http://www.anothersite.com/[some-params]

I tried to do this like that:

<LocationMatch ^/proxy/(.*)$>
    ProxyPassMatch http://$1
</LocationMatch>

But how can I make all redirects that sends to me remote host go via proxy? For example, if I go to url:

http://example.com/proxy/another-site.com

and another-site.com send me redirect to yet-another-site.com, it shall forward my browser to

http://example.com/proxy/yet-another-site.com
  • For more complex scenarios the P mod_rewrite directive can also (reverse) proxy requests similar to what is offered by the ProxyPass* directives. – HBruijn Aug 26 '16 at 19:15
0

You can use Apache ProxyPassReverse directive for this. You can find its documentation in Apache documentation

| improve this answer | |
  • Can I use ProxyPassReverse inside LocationMatch directive? Docs say that ProxyPassReverse will interpret the regexp literally as a path. So, I need to put ProxyPassReverse outside LocationMatch, but in that case I will lose remote host address, to which I am trying to proxy. :( – eliriand Aug 26 '16 at 14:31
0

I would recommend not using Location or LocationMatch blocks, just use the 2 argument versions of ProxyPass and ProxyPassMatch. So in your case:

ProxyPassMatch ^/proxy/(.*)$ http://$1

However you cannot use Apache configuration to fix back end redirects as there is no corresponging ProxyPassReverseMatch directive (this directive simply cannot work this way). You would need to edit Location, Content-Location and URI headers using the Header directive (which duplicates what the the ProxyPassReverse directive does) and possibly use mod_sed/mod_substitute to fix and hard coded URLs in the HTML.

But it will be messy, very messy. The reason this sort of thing is not easy to do is that in general Apache is not an HTML content aware server, it's an HTTP aware server, two very different things.

It maybe slightly easier to upgrade to apache v2.4 so you can use mod_proxy_html (which is HTML aware) or write your own handler in mod_lua or similar.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.