Problem:
I'm trying to configure apache as a reverse proxy where the remove server is specified in a query string parameter.
Let's say I'm serving a site at mywebapp.com. If you navigated to http://mywebapp.com/proxy?url=http://www.someothersite.com, then apache should act as a reverse proxy to http://www.someothersite.com. Similarly, if you navigated to http://mywebapp.com/proxy?url=https://login.notmysite.com, then apache should act as a reverse proxy to https://login.notmysite.com.
Considerations:
1. Rewrite relative urls in the response html to go through the proxy
2. Rewrite redirect responses from the remote server. For example, if the user requests mywebapp.com/proxy?url=https://login.notmysite.com and the remote server responds with a redirect to https://login.notmysite.com/, then the user's browser should see a redirect to mywebapp.com/proxy?url=https://login.notmysite.com/.
3. Support http and https
4. Support cookies
5. Reasonable security. I don't want to open a proxy for anyone in the world to use - it should only be used in an iframe on the site hosted at mywebapp.com.
Environment:
I'm using apache 2.2.24, but I can upgrade if that would make the problem easier to solve.
Current configuration:
<VirtualHost 127.0.0.1:8081>
ServerName www.mywebapp.com
SSLProxyEngine On
RewriteEngine on
RewriteCond %{QUERY_STRING} ^url=(.*)$
RewriteRule ^/proxy - [E=url:%1]
RewriteCond %{QUERY_STRING} ^url=(https?://[^:/]+)/?
RewriteRule ^/proxy - [E=url_host:%1]
RewriteCond %{QUERY_STRING} ^url=(.*)$
RewriteRule ^/proxy %1 [P]
ProxyPassInterpolateEnv On
ProxyPassReverse /proxy/ ${url_host} interpolate
<Location /proxy>
ProxyHTMLEnable On
ProxyHTMLInterp On
ProxyHTMLURLMap / ${url_host}/ V
RequestHeader unset Accept-Encoding
</Location>
</VirtualHost>
This configuration appears to be working correctly for consideration #1, but I hit a roadblock with consideration #2. I know that you usually handle redirects with the ProxyPassReverse command, but I'm not sure how get it to rewrite the query string parameter.
Questions:
Given the considerations, is Apache an appropriate tool for solving this problem?
If so, how do I setup the configuration for apache to meet all of the above considerations?
I know this is a big question - if you can contribute an answer that helps me meet just one of the considerations then I'll update the above configuration for the community to see.