0
votes

I have a following scenario:

  • Remote server with some webapp running at http://remote/webapp
  • Local machine inside corporate network
  • Corporate proxy between them
  • Apache with mod_rewrite running on my local machine

I would like to have the mod_proxy rewrite every request like http://localhost/webapp?someparams into http://remote/webapp?someparams.

Currently I have the following httpd.conf:

DocumentRoot "C:/Apache2.2/htdocs"

<Directory />
    RewriteEngine On
    RewriteRule ^(.+) http://remote/$1 
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Deny from all
</Directory>

Which results in mod_rewrite transforming http://localhost/webapp?someparams into http://remote/C:/Apache2.2/htdocs/webapp?someparams

How to configure mod_rewrite to handle it correctly?

2
I think that's called Reverse Proxying, you may want to look that up - Jonas Schäfer
I think Deny from all is the culprit here , Allow from all will work I think , can you try once and also , here your expectation is unpredictable , you are using windows absoute path in an URL , really not able to figure out what want - Aravind.HU
The fact that windows absolute path appears in the URL is due to misconfiguration of the mod_rewrite and this is what I'm trying to avoid. - s4nk

2 Answers

0
votes

Since it looks like you have access to vhost/server config, you should ditch mod_rewrite and just use mod_proxy:

ProxyPass /webapp http://remote/webapp
ProxyPassReverse /webapp http://remote/webapp

and get rid of the 2 mod_rewrite lines (which is redirecting, not proxying):

RewriteEngine On
RewriteRule ^(.+) http://remote/$1 

Note that if you have cookies, you may need to reverse map their domains.using ProxyPassReverseCookieDomain.


Also:

The fact that windows absolute path appears in the URL is due to misconfiguration of the mod_rewrite and this is what I'm trying to avoid

This is not a misconfiguration with mod_rewrite. When you put rewrite rules inside a <Directory>, the filepath is used in the match instead of the URI-path. According to the mod_rewrite documentation

What is matched?

In VirtualHost context, The Pattern will initially be matched against the part of the URL after the hostname and port, and before the query string (e.g. "/app1/index.html").

In Directory and htaccess context, the Pattern will initially be matched against the filesystem path, after removing the prefix that lead the server to the current RewriteRule (e.g. "app1/index.html" or "index.html" depending on where the directives are defined).

0
votes

Thank you Jon for inspiration, finally mod_proxy + mod_rewrite worked:

# Global context
RewriteEngine On
RewriteRule ^(.+) http://remote/$1 [P]
ProxyPassReverse / http://remote/

I know that this is a simplified and coarse solution, but works for my purpose.