#1 gxnnhuzz
路由配置如下:$config = array('rewrite' => array(
'
'/' => 'api/main/index',
),
);
当访问http://localhost时,报错没有找到MainController,可事实上MainController是存在的,actionIndex也存在,经跟踪后发现,speed.php第21行起的路由计算后发现:当$rule==/时,28行if(preg_match($rule, $GLOBALS['http_scheme'].$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $matchs)) 的$rule为http://locallhost//$,这个preg_match不成立,下面的自动生成m c a 的代码被跳过,导致找不到MainController,后来经过如下修改,初步解决这个问题,但希望jake检查一下以下代码会不会引发其它问题:
if('/' == $rule)
$rule = '/$';
if(0!==stripos($rule, $GLOBALS['http_scheme'])){
$url = $GLOBALS['http_scheme'].$_SERVER['HTTP_HOST'].rtrim(dirname($_SERVER["SCRIPT_NAME"]), '/\\') ;
if (preg_match("/\\/+$/",$url))
$rule = $url.$rule;
else{
if (preg_match("/^\\/+/",$rule)){
$rule = $url.$rule;
}else{
$rule = $url.'/'.$rule;
}
}
}
$rule = '/'.str_ireplace(array('\\\\', $GLOBALS['http_scheme'], '/', '<', '>', '.'),
array('', '', '\/', '(?P<', '>[-\w]+)', '\.'), $rule).'/i';
$testuri = $GLOBALS['http_scheme'].$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] ;
$testuri = preg_replace("/\\/+$/","/",$testuri) ;
2019-06-08 22:26:23