Looking for equivalent of ProxyPassReverseMatch in Apache to fix missing trailing forward slash issue

apache-2.2mod-proxymod-rewriteproxypass

I have two web servers, www.example.com and www.userdir.com. I'm trying to make www.example.com as the front end proxy server to serve requests like in the format of http://www.example.com/~username such as

http://www.example.com/~john/

so that it sends an internal request of

http://www.userdir.com/~john/

to www.userdir.com. I can achieve this in Apache with

ProxyPass /~john http://www.userdir.com/~john  
ProxyPassReverse /~john http://www.userdir.com/~john

The ProxyPassReverse is necessary as without it a request like http://www.example.com/~john without the trailing forward slash will be redirected as http://www.userdir.com/~john/ and I want my users to stay in the example.com space.

Now, my problem is that I have a lot of users and I cannot list all those user names in httpd.conf. So, I use

ProxyPassMatch ^(/~.*)$ http://www.userdir.com$1

but there is no such thing as ProxyPassReverseMatch in Apache. Without it, whenever the trailing forward slash is missing in the URL, one will be directed to www.userdir.com, and that's not what I want.

I also tried the following to add the trailing forward slash

RewriteCond %{REQUEST_URI} ^/~[^./]*$  
RewriteRule ^/(.*)$ http://www.userdir.com/$1/ [P]

but then it will render a page with broken image and CSS because they are linked to http://www.example.com/images/image.gif while it should be http://www.example.com/~john/images/image.gif.

I have been googling for a long time and still can't figure out a good solution for this. Would really appreciate it if any one can shed some light on this issue. Thank you!

Best Answer

You can just ignore the username and anything that follows when fixing up the redirect:

ProxyPassReverse /~ http://www.userdir.com/~

Since this is just a prefix substitution.