Rewrite with Array-Variables

Discuss practical ways rearrange URLs using mod_rewrite.

Rewrite with Array-Variables

Postby qtx » Mon Aug 18, 2008 12:51 am

Hi every1

Is there a way to build a mod_rewrite rule to overcome query strings with array-variables?

ef.
http://mypage.com?var[]=value1&var[]=value2&var[]=value3

I know how you can use regex to loop, but I have never seen a solution to do this with Apache's regex.

Any ideas?

Thanks a lot.
QT
qtx
 
Posts: 2
Joined: Mon Aug 18, 2008 12:47 am

Postby richardk » Mon Aug 18, 2008 4:55 pm

I know how you can use regex to loop

How?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby qtx » Tue Aug 19, 2008 12:05 am

richardk wrote:How?


Of course, that was not accurate, not just with regex's :)

I guess that there is no possibilty whatsoever without the help of a scripting language or system component.
qtx
 
Posts: 2
Joined: Mon Aug 18, 2008 12:47 am

Postby richardk » Wed Aug 20, 2008 11:32 am

You can do loops with mod_rewrite (for /test-0-1-2-3)
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^test-([^-]+)((-[^-]+)*)$ /test$2?%{QUERY_STRING}&var[]=$1
RewriteRule ^test$ /test.php [QSA,L]


But
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^test-(.+)$ /test.php?var=$1 [QSA,L]

and
Code: Select all
if(isset($_GET['var']) && !is_array($_GET['var']))
{
  $_GET['var'] = explode('-', $_GET['var']);
}

is probably a lot faster.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 14 guests

cron