I ahve apache httpd 2.2.15 (Unix) using mod_rewrite
I have this rewrite goingon:
RewriteEngine On
RewriteLogLevel 7
RewriteMap encode-map prg:/var/www/centos6.local/encode.pl
RewriteLog "/var/log/httpd/centos6.local-rewrite_log"
RewriteCond %{QUERY_STRING} CID=(.*)
RewriteRule .* - [L,CO=NDD_COOKIE:${encode-map:%1}:ndipiazza.test.local:50000]
The purpose of this is to detect if you find a CID=xyz anywhere in the query string. If you do, create a cookie NDD_COOKIE with xyz encoded by a custom perl script /var/www/centos6.local/encode.pl
This only sets the cookie once, then will not set the cookie again until the server restarts completely.
0) Set hosts file so that ndpiazza.test.local points to 192.168.2.7
1) Launch http://ndipiazza.test.local/test.html?CID=test123
Result: Encoded cookie is written as expected
2) Switch to fresh browser or clear browse cache.
3) Launch http://ndipiazza.test.local/test.html?CID=new567
Result: No cookie is written!
Here is a link to the encode.pl script
Why is this happening?
Here is the rewrite log for http://ndipiazza.test.local/test.html?UID=sfsfsfd888m when it did NOT work:
192.168.2.3 - - [28/Jun/2012:16:33:29 --0500] [ndipiazza.test.local/sid#7fc041c0c880][rid#7fc041d34608/initial] (2) init rewrite engine with requested uri /test.html
192.168.2.3 - - [28/Jun/2012:16:33:29 --0500] [ndipiazza.test.local/sid#7fc041c0c880][rid#7fc041d34608/initial] (3) applying pattern '.*' to uri '/test.html'
192.168.2.3 - - [28/Jun/2012:16:33:29 --0500] [ndipiazza.test.local/sid#7fc041c0c880][rid#7fc041d34608/initial] (4) RewriteCond: input='UID=sfsfsfd888' pattern='UID=(.*)' => matched
192.168.2.3 - - [28/Jun/2012:16:33:29 --0500] [ndipiazza.test.local/sid#7fc041c0c880][rid#7fc041d34608/initial] (5) map lookup OK: map=encode-map key=sfsfsfd888 -> val=
192.168.2.3 - - [28/Jun/2012:16:33:29 --0500] [ndipiazza.test.local/sid#7fc041c0c880][rid#7fc041d34608/initial] (5) setting cookie 'WS_CUID=ndipiazza.test.local; path=/; domain=50000'
192.168.2.3 - - [28/Jun/2012:16:33:29 --0500] [ndipiazza.test.local/sid#7fc041c0c880][rid#7fc041d34608/initial] (1) pass through /test.html
Answer: The system will open the encode.pl only once. It is expected to keep listening for stdin continuously.
But you can still use prg rewritemap to do this.
The big thing I was missing is that I needed a while loop in the in perl.
Here is what I ended up solved the problem with:
httpd.conf entry:
encode.pl: