All pastes #366989 Raw Edit

StarScream

public text v1 · immutable
#366989 ·published 2007-02-22 01:17 UTC
rendered paste body
Hi all, i am trying to set up a re-write rule

where all URL's basically consist of 
/controller/action/foo/bar/

the first two matches will map to $1 and $2 respectively
$1 = controller
$2 = action

however I basically would like the rest of the query string to be tacked on to 
vars ($3), regardless of how many /x/y/z/ come after it.

this is what i have at the moment which seems like it should work but i'm obviously doing something wrong, or  it doesn't work the way i think it does :)

RewriteRule ^/([^/\.]+)/([^/\.]+)/([^/\.]*)/$ /index?controller=$1&action=$2&vars=$3 [PT]

so if i had a URL

/products/view/id-4/lightsaber/

the re-written string would be 
index?controller=products&action=view&vars=<the following will be urlencoded of course>/id-4/lightstabber/ 

so within a programming language (php for example)
i could use
$controller = filter...($_GET['controller']);
$action = filter...($_GET['action']);
$vars = filter...(urluencode($_GET['vars']));

and $vars would = /id-4/lightsaber