Saturday, June 26, 2010

[HTTP][Apache] How to take a value from a header and put it in a new header using mod_proxy, mod_headers and mod_rewrite

Today I decided after 4 hours trying to figure out something I did a year ago. That from now on when I research a problem and find a solution, I will blog the solution so that I do not have waste time in future. To my surprise, I had already made a blog post in 2007 and my old blogger account still works...

I have tested that the following config in apache config file rewrites the header properly from a COOKIE to a new HTTP-HEADER.

RewriteEngine on
RewriteLog "/tmp/rewrite.log"
RewriteLogLevel 9
RewriteCond %{HTTP_COOKIE} (.*)x-up-calling-line-id=(.*);(.*)
RewriteRule .* - [E=in-msisdn:%2]
RequestHeader set "OUT-MSISDN" %{in-msisdn}e

The cookie was
curl http://localhost/ -H 'Cookie: JSESSIONID=FD92481E01852F97386A9B1F163534B7;x-up-calling-line-id=23387964521; Path=/towap'

And I received the msisdn in proper header OUT-MSISDN in server. Apache version is 2.2.8_Ubuntu with modules mod_headers and mod_rewrite