[php]
if(isset($_SERVER['PATH_INFO'])){
//獲取路徑信息(pathinfo)
$pathinfo=explode('/',trim($_SERVER['PATH_INFO'],'/'));
//獲取$_GET['m']
$_GET['m']=(!emptyempty($pathinfo[0])?$pathinfo[0]:'index');
//將數組單元的開頭移除
array_shift($pathinfo);
//獲取$_GET['a]
$_GET['a']=(!emptyempty($pathinfo[0])?$pathinfo[0]:'index');
//將數組單元的開頭移除
array_shift($pathinfo);
$num=count($pathinfo);
for ($i=0;$i<$num;$i+=2){
$_GET[$pathinfo[$i]]=$pathinfo[$i+1];
}
}else{
$_GET['m']=(!emptyempty($_GET['m'])?$_GET['m']:'index');
$_GET['a']=(!emptyempty($_GET['a'])?$_GET['a']:'index');
if($_SERVER["QUERY_STRING"]){
$m=$_GET['m'];
unset($_GET['m']); //去除數組的m
$a=$_GET['a'];
unset($_GET['a']); //去除數組的a
$query=http_build_query($_GET); //組成新的URL參數
//組合新的URL
$url=$_SERVER['SCRIPT_NAME']."/{$m}/{$a}/".str_replace(array("&","="),"/",$query);
header("Location:".$url);
}
}
if(isset($_SERVER['PATH_INFO'])){
//獲取路徑信息(pathinfo)
$pathinfo=explode('/',trim($_SERVER['PATH_INFO'],'/'));
//獲取$_GET['m']
$_GET['m']=(!empty($pathinfo[0])?$pathinfo[0]:'index');
//將數組單元的開頭移除
array_shift($pathinfo);
//獲取$_GET['a]
$_GET['a']=(!empty($pathinfo[0])?$pathinfo[0]:'index');
//將數組單元的開頭移除
array_shift($pathinfo);
$num=count($pathinfo);
for ($i=0;$i<$num;$i+=2){
$_GET[$pathinfo[$i]]=$pathinfo[$i+1];
}
}else{
$_GET['m']=(!empty($_GET['m'])?$_GET['m']:'index');
$_GET['a']=(!empty($_GET['a'])?$_GET['a']:'index');
if($_SERVER["QUERY_STRING"]){
$m=$_GET['m'];
unset($_GET['m']); //去除數組的m
$a=$_GET['a'];
unset($_GET['a']); //去除數組的a
$query=http_build_query($_GET); //組成新的URL參數
//組合新的URL
$url=$_SERVER['SCRIPT_NAME']."/{$m}/{$a}/".str_replace(array("&","="),"/",$query);
header("Location:".$url);
}
}