一、找到vendorworkermanworkermanWebServer.php?第176行,改為以下內(nèi)容,增加對(duì)html擴(kuò)展名文件不存在的判斷
????????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'; ????????????} ????????}
這樣以后,只要訪問擴(kuò)展名為html的文件,且這個(gè)文件不存在,就會(huì)自動(dòng)重定向到index.php,然后再在index.php進(jìn)行判斷就行了
二、index.php改造,輸出頁(yè)面前,增加以下判斷:
//重定向判斷 $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
立即學(xué)習(xí)“PHP免費(fèi)學(xué)習(xí)筆記(深入)”;
三、根據(jù)$_GET[‘_’],分割下劃線,判斷加載哪一個(gè)類和類的方法,就行了。比如:
$_GET['_']=isset($_GET['_'])?$_GET['_']:strcode('Index_index'); $strs=strcode($_GET['_'],'DECODE'); if(!$strs)xdie('param?error.'); $d=preg_split('/[._]/',$strs); if(count($d)<p>再加載類并運(yùn)行就行了。</p><p>更多workerman知識(shí)請(qǐng)關(guān)注PHP中文網(wǎng)<a href="https://www.php.cn/workerman/" target="_blank">workerman教程</a>欄目。</p>
? 版權(quán)聲明
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載。
THE END
喜歡就支持一下吧
相關(guān)推薦