views:

181

answers:

2

Hi!

I have an application running under tomcat 6. In front of it I have an apache server which is forwarding all requests. That is, the user "talks" to the apache and not to tomcat. For some reasons the it is requested the following: when the apache server receives a request of the form

http://www.mydomain.com/myApp

then it has to be forwarded to http://www.mydomain.com/$PREFIX/myApp

where $PREFIX is a POST parameter. This $PREFIX parameter is also available as a COOKIE and as a extra header. I didn't find a way using mod_rewrite for reading post parameters/cookies/headers.

Is this possible at all? If not, should I use another apache module/connector?

Thanks in advance.

Luis

+1  A: 

You can't use POST data for mod_rewrite. This is because the POST data isn't in the HEADER of the http request, it's in the BODY.

My suggestion would be that you perform an action on the posting page that adds the prefix to the URL, which would mean you don't even need to rewrite.

Sohnee
Thanks for your answer. Is it possible to do this using cookies or extra header params? What are you suggesting is not possible because it has to be done not only at the application but also at evey used plugin, etc. Actually this was my first approach but I#ve abbandoned it due to the huge amount of work that this generates. I have to find a higher level solution.
Luixv
+1  A: 

try something like (my regex is a bit flakey so may need a bit of tinkering):

RewriteCond %{HTTP_COOKIE} yourcookie=(.*)
RewriteRule ^/myApp(.*)$ /%1/$1 [R,L]

The %1 will backreference to groups in the RewriteCond pattern.

More examples here

SeriousCallersOnly
Thanks for your answer. I am trying with something similar. +1 for you :-)
Luixv