I've set up an Apache HTTP server with VirtualHosts in front of a proprietary web server in the back. The backend server can only have one (1) level in its ID paths so the following public URLs:
http://public-server/path1/path2/path3?querystring-parameters
should be converted for the backend to:
http://internal-server/path1/path2/page/<path1>_<path2>_<path3>?querystring-parameters
Notice that there can be any number of path1, path2, path3, path4, .... and they should all (no matter if only 1 exis开发者_开发知识库ts or multiple) be concatenated with an underscore. Also notice that the querystring-parameters CAN contain '?', '/' and '_' so the rule should not alter the querystring in any way.
I've tried searching for solutions to this but can't figure out how to overcome the problem. Any suggestions?
If you can come up some maximum number of possible paths, you can do something to this effect:
# This will work for up to 5 paths
RewriteRule /([^/]*)/?([^/]*)/?([^/]*)/?([^/]*)/?([^/]*) http://internal-server%{REQUEST_URI}$1_$2_$3_$4_$5 [L,QSA]
The /?([^/]*) can be added to the end as many times as you need, along with added the corresponding groups (_$6 ..) to the rewritten URL.
Unfortunately, there is not a way have a completely unknown number of paths, while at the same time use them in the rewritten URL. Also, the [QSA] flag will attach your querystring on to the forwarded URL, untouched.
Hope this helps.
精彩评论