I found a solution for this conversion without changing the code.
In httpd.conf (in the VirtualHost section), I define a rewrite map:
RewriteMap programmap prg:/var/www/localhost/htdocs/chg.php
Then in .htaccess I set the following rules:
RewriteEngine On RewriteCond %{QUERY_STRING} (.*) RewriteRule ^(script.php) $1?${programmap:%1} [L]
$ 1 for the first "()" in a RewriteRule
% 1 stands for first "()" in RewriteCond
Then I write this script "/var/www/localhost/htdocs/chg.php" (in PHP, but maybe in C, Perl or whatelse):
#!/usr/bin/php -f <?php $pos1 = 2; $pos2 = $pos1 + 1; $reg = '/(([a-z0-9_]+)\[\]=([^&]*))/'; while(true){ $res=array(); $buff = trim(fgets(STDIN)); if(feof(STDIN)){ break; } $r = preg_match_all($reg, $buff, $match,PREG_SET_ORDER); if($r){ foreach($match as $row){ if(!isset($res[$row[$pos1]])){ $res[$row[$pos1]] = $row[$pos1]."=".$row[$pos2]; } else { $res[$row[$pos1]] .= ",".$row[$pos2]; } } $out=join('&',$res); } else { $out=$buff; } echo "$out\n"; }
source share