一、找到\vendor\workerman\workerman\WebServer.php 第176行,改爲以下內容,增加對html擴展名文件不存在的判斷
if (in_array($workerman_file_extension,['php','html']) && !is_file($workerman_file)) {
$workerman_file = "{$workerman_root_dir}/index.php";
$workerman_file_extension = 'php';
if (!is_file($workerman_file)) {
$workerman_file = "{$workerman_root_dir}/index.html";
$workerman_file_extension = 'html';
}
}
這樣以後,只要訪問擴展名爲html的文件,且這個文件不存在,就會自動重定向到index.php,然後再在index.php進行判斷就行了
二、index.php改造,輸出頁面前,增加以下判斷:
//重定向判斷
$uri=$_SERVER['REQUEST_URI'];
$ext=strtolower(substr($uri,-4,4));
if(is_cli()&&$ext=='html'){
$_GET['_']=substr($uri,1,strlen($uri)-5);
}
比如,我訪問的地址是http://c.com/Users_login.html,即訪問index.php?_=Users_login
三、根據$_GET['_'],分割下劃線,判斷加載哪一個類和類的方法,就行了。比如:
$_GET['_']=isset($_GET['_'])?$_GET['_']:strcode('Index_index');
$strs=strcode($_GET['_'],'DECODE');
if(!$strs)xdie('param error.');
$d=preg_split('/[\.\_]/',$strs);
if(count($d)<2)xdie('error:param');
$class=$d[0].'Action';
$action=$d[1];
再加載類並運行就行了。