DEDEBIZ偽靜態(tài)URL地址和生成靜態(tài)URL地址保持一致的方法

DEDEBIZ是由原DEDECMS開(kāi)發(fā)而來(lái)的,DedeBIZ系統(tǒng)基于PHP7版本開(kāi)發(fā),代碼進(jìn)行了優(yōu)化重構(gòu),延續(xù)之前的標(biāo)簽,以前的模板拿過(guò)來(lái)都是可以直接使用的,如果原來(lái)用的DEDECMS的系統(tǒng),執(zhí)行一下升級(jí)程序, 就可以轉(zhuǎn)到DEDEBIZ程序,DEDEBIZ對(duì)URL地址進(jìn)行了修改,如果是生成靜態(tài),URL地址是和以前DEDCMS一樣的,如果是用偽靜態(tài),它的地址全部改寫(xiě)了,即下面格式:

欄目URL地址為:網(wǎng)址/list/欄目ID(如欄目一的URL地址為/list/1,欄目二的URL地址為/list/2,欄目三的URL地址為/list/3)

欄目分頁(yè)URL地址為:網(wǎng)址/list/欄目ID-頁(yè)碼

內(nèi)容頁(yè)URL地址:網(wǎng)址/article/文章ID.html

內(nèi)容分頁(yè)URL地址:網(wǎng)址/article/文章ID-頁(yè)碼.html

欄目和內(nèi)容頁(yè)的URL地址里都是固定死了,只是后面的ID不同。

而以前的DEDECMS的URL地址為:

列表頁(yè)? http://www.xxxx.com/news/
列表分頁(yè) http://www.xxxxcom/news/list_1_2.html
內(nèi)容頁(yè)??? http://www.xxxx.com/xinwenzixun/6.html
內(nèi)容頁(yè)分頁(yè)? http://www.xxxx.com/news/6_2.html

如果是以前的老站轉(zhuǎn)過(guò)來(lái)的話,那么URL地址全變了,以前的收錄也就全廢了。跟官方反映過(guò)這個(gè)問(wèn)題,他們堅(jiān)持用現(xiàn)在新的URL規(guī)則。如果想用跟以前一樣的URL,得自己二開(kāi)或者跟官方定制。

如果你是想做企業(yè)站。生成靜態(tài)URL地址能沒(méi)啥問(wèn)題,但如果你要用偽靜態(tài),那新聞欄目的URL就為/list/1 ,產(chǎn)品欄目為/list/2,URL里面的list是固定的,通過(guò)欄目的URL地址,你不知道它是啥欄目,以前的/xinwen/或者/news/一眼就可以看出啥欄目,后臺(tái)欄目生成目錄的地方你填的啥,你的目錄就是啥名,這樣的URL也方便SEO。

我這里以DEDEBIZ6.5版本為例進(jìn)行修改,主要實(shí)現(xiàn)列表頁(yè)、內(nèi)容頁(yè)、TAG標(biāo)簽頁(yè)的偽靜態(tài)。

準(zhǔn)備工作:安裝好DEDEBIZ系統(tǒng),打開(kāi)后臺(tái)系統(tǒng)設(shè)置,開(kāi)啟偽靜態(tài),如果你現(xiàn)在的站全是靜態(tài),得把它全部轉(zhuǎn)成動(dòng)態(tài),一健靜態(tài)轉(zhuǎn)動(dòng)態(tài)方法?DEDEBIZ動(dòng)靜態(tài)切換插件 如果是有數(shù)據(jù)的站,請(qǐng)?zhí)崆皞浞莺脭?shù)據(jù)。

偽靜態(tài)設(shè)置成功后,訪問(wèn)URL地址效果如下:

列表頁(yè)?? ? ? ? ?http://www.123.com/news/
列表分頁(yè)? ? ? ? ?http://www.123.com/news/list-1-2.html
內(nèi)容頁(yè)??? http://www.123.com/xinwenzixun/6.html
內(nèi)容頁(yè)分頁(yè)? http://www.123.com/news/6-2.html
TAG標(biāo)簽頁(yè)? http://www.123.com/tags/126/
TAG標(biāo)簽分頁(yè) http://www.123.com/tags/126/2/

如果你是新站,不在意URL的問(wèn)題,只是想使用偽靜態(tài),后臺(tái)開(kāi)啟偽靜態(tài)后,只需要使用下面的偽靜態(tài)規(guī)則即可實(shí)現(xiàn)列表,內(nèi)容頁(yè)的偽靜態(tài)

偽靜態(tài)規(guī)則(Nginx)

#內(nèi)容頁(yè)及內(nèi)容頁(yè)分頁(yè)
rewrite ^/article/([0-9]+).html$ /apps/view.php?aid=$1;
rewrite ^/article/([0-9]+)-([0-9]+).html$ /apps/view.php?aid=$1&PageNo=$2;
#列表頁(yè)及列表分頁(yè)
rewrite ^/list/([0-9]+)$ /apps/list.php?tid=$1;
rewrite ^/list/([0-9]+)-([0-9]+)$ /apps/list.php?tid=$1&PageNo=$2;
#TAG標(biāo)簽
rewrite ^/tags\.html$ /apps/tags.php;
rewrite ^/tags/(.*)(?:(\?.*))* /apps/tags.php?\/$1;
rewrite ^/tags/(.*)\/(?:(\?.*))* /apps/tags.php?\/$1\/;
rewrite ^/tags/(.*)\/([0-9])(?:(\?.*))* /apps/tags.php?\/$1\/$2;
rewrite ^/tags/(.*)\/([0-9])\/(?:(\?.*))* /apps/tags.php?\/$1\/$2\/;

設(shè)置好后,它的URL地址效果如下:

列表頁(yè)?? ? ? ? ?http://www.123.com/list/1
列表分頁(yè)? ? ? ? ?http://www.123.com/lsit/1-2.html
內(nèi)容頁(yè)??? http://www.123.com/article/6.html
內(nèi)容頁(yè)分頁(yè)? http://www.123.com/article/6-2.html
TAG標(biāo)簽頁(yè)? http://www.123.com/tags/126/
TAG標(biāo)簽分頁(yè) http://www.123.com/tags/126/2/

TAG的偽靜態(tài)開(kāi)啟后,它的URL路徑里會(huì)包含/app/tags.php?/,可以參考下面的TAG修改方法即可實(shí)現(xiàn)上面的URL效果。

廢話也不多說(shuō)了。開(kāi)始教程

第一步:列表頁(yè)

1、列表頁(yè)

打開(kāi)system\helpers\channelunit.helper.php,大約在145行,

$reurl = $GLOBALS['cfg_cmspath']."/list/".$typeid;

修改為:

$reurl = $GLOBALS['cfg_cmspath']."/{$typedir}/";

修改前它的URL地址為/list-1,修改后:/欄目名稱

打開(kāi)/apps/list.php搜索

$tid = (isset($tid) && is_numeric($tid) ? $tid : 0);

大約在13行,把它修改為:

if($cfg_rewrite == 'Y')
{
    if(!is_numeric($tid))
    {
        $typedir = parse_url($tid, PHP_URL_PATH);
        $PageNo = stripos(GetCurUrl(), '.html') ? intval(str_replace('.html', '', end(explode("-", GetCurUrl())))) : 1;
        $tinfos = $dsql->GetOne("SELECT * FROM `#@__arctype` WHERE typedir='/$typedir' or typedir='{cmspath}/$typedir'");

        if(is_array($tinfos))
        {
            $tid = $tinfos['id'];
            $typeid = GetSonIds($tid);
            $row = $dsql->GetOne("Select count(id) as total From `#@__archives` where typeid in({$typeid})");
        }
        else
        {
            $tid = 0;
        }
    }
}
else
{
	$tid = (isset($tid) && is_numeric($tid) ? $tid : 0);
}

2、列表分頁(yè):

打開(kāi)/archive/listview.class.php,查找://偽靜態(tài)欄目分頁(yè) ,大約在1204行

        if ($cfg_rewrite == 'Y') {
            $plist = str_replace("?tid=", "", $plist);
            $plist = preg_replace("/&pageno=(\d+)/i", "-\\1", $plist);
            $plist = preg_replace("/&TotalResult=(\d+)/i", "", $plist);//去掉分頁(yè)數(shù)值
        }
        return $plist;
    }

修改為:

        if ($cfg_rewrite == 'Y') {
            $plist = str_replace("?tid=", "list-", $plist);
            $plist = preg_replace("/&pageno=(\d+)/i", "-\\1.html", $plist);
            $plist = preg_replace("/&TotalResult=(\d+)/i", "", $plist);//去掉分頁(yè)數(shù)值
        }
        return $plist;
    }

修改前:/list-欄目id-頁(yè)碼
修改后:/欄目/list-欄目id-頁(yè)碼

注意,我這里把URL中間的連接符由下橫線_換成-了,如果你想要下橫線,請(qǐng)修改上面的-,list.php里面的explode("-",也要修改。不然列表分頁(yè)報(bào)500錯(cuò)誤。

第二步:內(nèi)容頁(yè)

1、內(nèi)容頁(yè)

打開(kāi)system\helpers\channelunit.helper.php,搜索:

if (!function_exists('GetFileName'))

大約在196行,把196行到241行里的全部替換為:

if (!function_exists('GetFileName')) {
    function GetFileName($aid, $typeid, $timetag, $title, $ismake = 0, $rank = 0, $namerule = '', $typedir = '', $money = 0, $filename = '')
    {
        global $cfg_cmspath, $cfg_arcdir, $cfg_special, $cfg_arc_dirname, $cfg_rewrite;
        
        // 清理路徑中的特殊標(biāo)記和多余斜杠
        $cleanPath = function($path) {
            return trim(str_replace(['{cmspath}', '//'], ['', '/'], $path), '/');
        };
        
        // 獲取規(guī)范化欄目目錄
        $getTypedir = function($typeid, $typedir) use ($cleanPath) {
            if (!empty($typedir)) {
                return $cleanPath($typedir);
            }
            if ($typeid > 0) {
                $row = GetOne("SELECT typedir FROM `#@__arctype` WHERE id='$typeid'");
                return $cleanPath($row['typedir'] ?? 'default');
            }
            return 'default';
        };

        // 沒(méi)指定欄目時(shí)用固定專題規(guī)則
        if (empty($namerule)) {
            $namerule = $cfg_special.'/{aid}.html';
            $typeid = -1;
        }
        
        // 動(dòng)態(tài)文檔處理
        if ($rank != 0 || $ismake == -1 || $typeid == 0 || $money > 0) {
            if ($cfg_rewrite == 'Y') {
                $typedir = $getTypedir($typeid, $typedir);
                return "/{$typedir}/{$aid}.html"; // 格式:/欄目名/文章ID.html
            } else {
                return $GLOBALS['cfg_phpurl']."/view.php?aid=$aid";
            }
        } 
        // 靜態(tài)文檔處理
        else {
            $articleDir = $cleanPath(MfTypedir($typedir));
            $articleRule = strtolower($namerule);
            
            if ($articleRule == '') {
                $articleRule = strtolower($GLOBALS['cfg_df_namerule']);
            }
            
            if ($typedir == '') {
                $articleDir = $cleanPath($GLOBALS['cfg_cmspath'].$GLOBALS['cfg_arcdir']);
            }
            
            $dtime = GetDateMk($timetag);
            list($y, $m, $d) = explode('-', $dtime);
            
            $arr_rpsource = array('{typedir}', '{y}', '{m}', '048jcw27883r', '{timestamp}', '{aid}', '{cc}');
            $arr_rpvalues = array(
                $articleDir, 
                $y, $m, $d, 
                $timetag, 
                $aid, 
                dd2char($m.$d.$aid.$y)
            );
            
            if ($filename != '') {
                $articleRule = dirname($articleRule).'/'.$filename.$GLOBALS['cfg_df_ext'];
            }
            
            $articleRule = str_replace($arr_rpsource, $arr_rpvalues, $articleRule);
            
            if (preg_match("/\{p/", $articleRule)) {
                $articleRule = str_replace('{pinyin}', GetPinyin($title).'-'.$aid, $articleRule);
                $articleRule = str_replace('{py}', GetPinyin($title, 1).'-'.$aid, $articleRule);
            }
            
            $articleUrl = '/'.preg_replace("/^\//", '', $articleRule);
            
            if (preg_match("/index\.html/", $articleUrl) && $cfg_arc_dirname == 'Y') {
                $articleUrl = str_replace('index.html', '', $articleUrl);
            }
            
            return $articleUrl;
        }
    }
}

打開(kāi)\apps\view.php

搜索:$t1 = ExecTime(); 大約在13行,在它下面添加

// 修改URL重寫(xiě)部分
if($cfg_rewrite == 'Y')
{
    if(!is_numeric($aid))
    {
        $currentUrl = GetCurUrl();
        if(stripos($currentUrl, '.html') !== false) {
            // 解析URL格式:/欄目名/文章ID-頁(yè)碼.html
            $urlParts = explode('/', trim($currentUrl, '/'));
            $lastPart = str_replace('.html', '', end($urlParts));
            
            // 分離文章ID和頁(yè)碼
            $aidParts = explode('-', $lastPart);
            $aid = isset($aidParts[0]) ? intval($aidParts[0]) : 0;
            $pageno = isset($aidParts[1]) ? intval($aidParts[1]) : 1;
            
            if($aid > 0) {
                $_GET['pageno'] = $pageno;
                $GLOBALS['pageno'] = $pageno;
            }
        }
    }
    
    if($aid > 0) {
        $arcrow = GetOneArchive($aid);
        if(is_array($arcrow)) {
            // 驗(yàn)證URL時(shí)忽略頁(yè)碼部分
            $baseUrl = preg_replace('/-\d+\.html$/', '.html', GetCurUrl());
            $typedir = str_replace('{cmspath}/', '', $arcrow['typedir']);
            $typedir = trim($typedir, '/');
            $expectedUrl = '/'.$typedir.'/'.$aid.'.html';
            
            if ($baseUrl != $expectedUrl) {
                header("HTTP/1.0 404 Not Found");
                die("Request Error: URL不匹配");
            }
        }
    }
}

修改后,內(nèi)容頁(yè)的URL由/article/文章ID.html,變成/欄目名稱/文章ID.html

2、內(nèi)容分頁(yè)

打開(kāi)\system\archive\archives.class.php,搜索: 獲得動(dòng)態(tài)文檔分頁(yè)列表? ,大約在919行,把它下面的代碼全部替換為:

function GetPagebreakDM($totalPage, $aid) 
{
    // 0. 單頁(yè)內(nèi)容直接返回空字符串
    if ($totalPage <= 1) {
        return "";
    }

    // 1. 安全驗(yàn)證(關(guān)鍵修復(fù))
    if(empty($aid) || $aid == 1) {
        preg_match('/\/(\d+)(?:-|\.)/', $_SERVER['REQUEST_URI'], $matches);
        $aid = $matches[1] ?? $this->ArcID ?? 0;
        if($aid == 0) return ""; // 改為靜默失敗
    }

    // 2. 獲取當(dāng)前頁(yè)碼
    $nowPage = 1;
    if (preg_match('/-(\d+)\.html$/', $_SERVER['REQUEST_URI'], $matches)) {
        $nowPage = (int)$matches[1];
    }

    // 3. 處理欄目目錄
    $typedir = $this->TypeLink->TypeInfos['typedir'];
    $typedir = str_replace(['{cmspath}/', '{typedir}/'], '', $typedir);
    $typedir = trim($typedir, '/');

    // 4. 構(gòu)建分頁(yè)HTML
    $PageList = "<ul class='pagination justify-content-center'>";
    $PageList .= "<li class='page-item disabled'><span class='page-link'>共{$totalPage}頁(yè)</span></li>";

    // 上一頁(yè)(僅當(dāng)不是第一頁(yè)時(shí)顯示)
    if ($nowPage > 1) {
        $prevUrl = ($nowPage - 1 == 1) 
            ? "/{$typedir}/{$aid}.html" 
            : "/{$typedir}/{$aid}-".($nowPage - 1).".html";
        $PageList .= "<li class='page-item'><a class='page-link' href='{$prevUrl}'>上頁(yè)</a></li>";
    }

    // 頁(yè)碼列表
    for ($i = 1; $i <= $totalPage; $i++) {
        $pageUrl = ($i == 1) 
            ? "/{$typedir}/{$aid}.html" 
            : "/{$typedir}/{$aid}-{$i}.html";
        
        $PageList .= ($i == $nowPage)
            ? "<li class='page-item active'><span class='page-link'>{$i}</span></li>"
            : "<li class='page-item'><a class='page-link' href='{$pageUrl}'>{$i}</a></li>";
    }

    // 下一頁(yè)(僅當(dāng)不是最后一頁(yè)時(shí)顯示)
    if ($nowPage < $totalPage) {
        $PageList .= "<li class='page-item'><a class='page-link' href='/{$typedir}/{$aid}-".($nowPage + 1).".html'>下頁(yè)</a></li>";
    }

    return $PageList;
}

修改后由/article/文章ID-頁(yè)碼.html變成/欄目名稱/文章ID-頁(yè)碼.html

第三步:TAG標(biāo)簽

DEDEBIZ的TAG標(biāo)簽已經(jīng)優(yōu)化好了。不過(guò)它是以ID形式出來(lái)的。URL為/tags/209,但它默認(rèn)的顯示是/app/tags.php?/209,我們把它URL地址修改一下就可以了。

 

打開(kāi)\system\taglib\tag.lib.php,大約在58行

$row['link'] = $cfg_cmsurl."/apps/tags.php?/".$row['id'];

修改為:

$row['link'] = $cfg_cmsurl."/tags/".$row['id'];

如果你列表頁(yè)也有調(diào)用TAG,請(qǐng)參考下面文章:DEDEBIZ內(nèi)容頁(yè)、列表頁(yè)調(diào)用當(dāng)前文章的TAG標(biāo)簽

里面的TAG標(biāo)簽的URL也需要修改,這里就不多說(shuō)了。

下面是偽靜態(tài)規(guī)則:

#TAG標(biāo)簽
rewrite ^/tags\.html$ /apps/tags.php;
rewrite ^/tags/(.*)(?:(\?.*))* /apps/tags.php?\/$1;
rewrite ^/tags/(.*)\/(?:(\?.*))*  /apps/tags.php?\/$1\/;
rewrite ^/tags/(.*)\/([0-9])(?:(\?.*))* /apps/tags.php?\/$1\/$2;
rewrite ^/tags/(.*)\/([0-9])\/(?:(\?.*))*  /apps/tags.php?\/$1\/$2\/;
#列表頁(yè)
rewrite ^/(.*)/$ /apps/list.php?tid=$1;
#列表分頁(yè)
rewrite ^/(.*)/list-([0-9]+)-([0-9]+)\.html$ /apps/list.php?tid=$1&PageNo=$2;
#文章頁(yè)
rewrite ^/(.*)/([0-9]+).html$ /apps/view.php?aid=$2 last;
#文章分頁(yè) URL:/欄目名/文章ID-頁(yè)碼.html
rewrite ^/(.*)/([0-9]+)-([0-9]+)\.html$ /apps/view.php?aid=$2&PageNo=$3 last;

END

THE END
亚洲中文色欧另类欧美,久久久久久久激情,亚洲 日韩 欧美 另类 国产,中文字幕高清无码男人的天堂 www.sucaiwu.net