我使用 mod_rewrite 使用 apache httpd 2.2.15 (Unix)
我正在进行这个重写:
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]
这样做的目的是检测您是否在查询字符串的任何位置找到 CID=xyz。如果这样做,请创建一个带有 xyz 的 cookie NDD_COOKIE,由自定义 perl 脚本 /var/www/centos6.local/encode.pl 编码
这只会设置一次cookie,然后在服务器完全重新启动之前不会再次设置cookie。
0) 设置 hosts 文件,使 ndpiazza.test.local 指向 192.168.2.7
1) 启动http://ndipiazza.test.local/test.html?CID=test123
结果:编码的cookie按预期写入
2)切换到新的浏览器或清除浏览缓存。
3) 启动http://ndipiazza.test.local/test.html?CID=new567
结果:没有写入cookie!
为什么会这样?
这是http://ndipiazza.test.local/test.html?UID=sfsfsfd888m在它不起作用时的重写日志:
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