Search code examples
apachehttpmod-rewritewebservermod-proxy

Using RewriteRule's resulting url(regex) in ProxyPassReverse


My webserver is hosting many apps whose path looks like

http://example.com/app1/
http://example.com/app2/ ...

I wanted to have temporary links to these apps which can be easily configured to be expired. So I have maintained mapping of temp to app url with expiry time in mysql. In apache I have written rewrite rule as below

RewriteEngine On
RewriteMap linkmap prg:/home/http/a.php

RewriteCond $1 ^[^/]*$
RewriteRule /(.*) /$1/ [R=301,L]
RewriteRule /(.*) /${linkmap:$1} [P]

a.php maps temp urls to actual urls using mysql db. For example temp1/xyz --> app1/xyz

Everything works fine until any page in app1 tries to redirect to another page. Since I am mapping urls based on mysql, I am not able to figure out how to make ProxyPassReference to read from mysql and replace redirect urls. I have tried to specify ProxyPassReference rule manually and it works. But it is not possible to add all rules manually since I can dynamically create links through some interface by inserting links to mysql db.

Please help me to handle redirects.


Solution

  • I have figured it out how to do it. So from rewriterule I get target url map which I save i regular expression. Then I used ProxyPassReverse with interpolate flag.

    There is one problem here. My program to map url is in php. It works fine but If I see it after few days, it seems program is stopped and I get server error then needs to restart server.