How is it possible to rewrite the query string like:
test.php?cat1[]=18&cat1[]=687&xxx[]=5&xxx[]=3&xxx[]=1&yyy[]=6
to
test.php?cat1=18,687,5&xxx=3,1&yyy=6
Note that the parameters (name and value pairs) are generated dynamically.
How is it possible to rewrite the query string like:
test.php?cat1[]=18&cat1[]=687&xxx[]=5&xxx[]=3&xxx[]=1&yyy[]=6
to
test.php?cat1=18,687,5&xxx=3,1&yyy=6
Note that the parameters (name and value pairs) are generated dynamically.
You must be logged in to post a comment.
Here’s a short php script that creates the query string that you want. It’s best not to do this part using mod_rewrite, because it’s simply outside of that scope:
If you save that script as
/rewrite.php
, for example, then you can include these rules in the .htaccess file to reroute requests with query strings containing arrays to/rewrite.php
:Then the rewrite.php script will rewrite the query string and redirect the browser with the concatenated query string.
test.php?cat1=18,687,5&xxx=3,1&yyy=6
try to insert this function before your code:
will print
I found a solution to do this transformation without modifying the code.
In the httpd.conf (in my VirtualHost section) I define a rewrite map:
Then in the .htaccess I set the following rules:
$1 stand for first “()” in RewriteRule
%1 stand for first “()” in RewriteCond
Then I write this script “/var/www/localhost/htdocs/chg.php” (in PHP but can be in C, Perl, or whatelse):