首頁  >  文章  >  php框架  >  php workerman偽靜態改造詳解

php workerman偽靜態改造詳解

尚
轉載
2020-01-03 16:27:372906瀏覽

php workerman偽靜態改造詳解

一、找到\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(&#39;error:param&#39;);
  
$class=$d[0].&#39;Action&#39;;
$action=$d[1];

再載入類別並運行就行了。

更多workerman知識請關注PHP中文網workerman教學專欄。

以上是php workerman偽靜態改造詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:csdn.net。如有侵權,請聯絡admin@php.cn刪除