views:

145

answers:

1

I'm a total n00b at mod_rewrite and what I'm trying to do sounds simple:

instead of having domain.com/script.php?a=1&b=2&c=3 I would like to have:

domain.com/script|a:1;b:2;c:3

The problem is that my script takes a large number of parameters in a variety of combinations, and order is unimportant, so coding each one in the expression and expecting a certain order is unfeasible. So can a rule be set up that simply passes all of the parameters to the script, regardless of order or how many parameters? So that if someone types

domain.com/script|a:1;b:2;j:7 it will pass all those params and values just the same as it would with domain.com/script|b:2;a:1; ?

Thanks!

+1  A: 

I would use PHP to parse the requested URL path:

$_SERVER['REQUEST_URI_PATH'] = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$params = array();
foreach (explode(',', substr($_SERVER['REQUEST_URI_PATH'], 6)) as $param) {
    if (preg_match('/^([^:]+):?(.*)$/', $param, $match)) {
        $param[rawurldecode($match[1])] = rawurldecode($match[2]);
    }
}
var_dump($params);

And the mod_rewrite rule to rewrite such requests to your /script.php file:

RewriteRule ^script\|.+ script.php [L]
Gumbo
ok that worked! was having a little mapping trouble but I got it. Thanks!
nerdabilly