首頁 > php框架 > Workerman > 主體

php workerman偽靜態改造詳解

發布: 2021-02-01 12:08:58
轉載
2948 人瀏覽過

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
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!