Apache mod_rewrite question

2019-08-23 10:22发布

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

2条回答
SAY GOODBYE
2楼-- · 2019-08-23 10:54

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

查看更多
smile是对你的礼貌
3楼-- · 2019-08-23 11:02

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.

查看更多
登录 后发表回答