The following is happening:
index.php?url=/controller/action/
then your $_GET['url']
is filled with this address url=/controller/action/
!!!
To recover effectively use $_SERVER['REQUEST_URI']
that it will bring: /controller/action/?q=nome
.
Ready now, just work with this value:
1) Simple example:
$url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI']: '';
if ($url != ''){
$urls = explode('/', $url);
$param = str_replace('?','', end($urls));
$param = explode('&', $param);
$params = array();
foreach($param as $pa){
$vp = explode('=', $pa);
$params[$vp[0]] = sizeof($vp)==2?$vp[1]:NULL;
}
//só para imprimir valor na tela!!! var_dump
var_dump($params);
}
Result:
2)Examplewith < strong> parse_url
var_dump(parse_url($_SERVER['REQUEST_URI']));
Result:
array(2) { ["path"]=> string(19) "/controller/action/" ["query"]=> string(6) "q=nome" }
Reference