織夢(mèng)Dedecms設(shè)置偽靜態(tài)詳細(xì)方法

字號(hào):


    dedecms默認(rèn)是不支持偽靜態(tài),如果要設(shè)置偽靜態(tài)我們需要懂一點(diǎn)程序基礎(chǔ)知識(shí)了,下面我來(lái)給大家介紹在apache下實(shí)現(xiàn)Dedecms設(shè)置偽靜態(tài)方法,有需要的朋友可參考一下
    首先在dede后臺(tái)開(kāi)啟偽靜態(tài)(開(kāi)啟的方法在系統(tǒng)參數(shù)-核心設(shè)置)
    第一步. 首先欄目和文章最好設(shè)置成動(dòng)態(tài)瀏覽. 這樣才不會(huì)生成靜態(tài)html文件.
    第二步. 設(shè)置重寫(xiě)規(guī)則. 在系統(tǒng)目錄下加一個(gè) .htaccess文件. 內(nèi)容為:
    代碼如下:
    RewriteEngine On
    RewriteRule ^plus/list-([0-9]+).html$ /plus/list.php?tid=$1
    RewriteRule ^plus/list-([0-9]+)-([0-9]+)-([0-9]+).html$ /plus/list.php?tid=$1&totalresult=$2&PageNo=$3
    RewriteRule ^plus/view-([0-9]+)-1.html$ /plus/view.php?arcID=$1
    RewriteRule ^plus/view-([0-9]+)-([0-9]+).html$ /plus/view.php?aid=$1&pageno=$2
    iis文件寫(xiě)法
    代碼如下:
    #首頁(yè)偽靜態(tài)規(guī)則,如果不使用動(dòng)態(tài)首頁(yè),請(qǐng)勿必刪除這一行,否則打開(kāi)首頁(yè)會(huì)出現(xiàn)死循環(huán)
    RewriteRule ^(.*)/index.html $1/index.php [I]
    #列表頁(yè)偽靜態(tài)規(guī)則
    RewriteRule ^(.*)/category/list-([0-9]+).html $1/plus/list.php?tid=$2 [I]
    RewriteRule ^(.*)/category/list-([0-9]+)-([0-9]+)-([0-9]+).html $1/plus/list.php?tid=$2&TotalResult=$3&PageNo=$4 [I]
    #文章頁(yè)偽靜態(tài)規(guī)則
    RewriteRule ^(.*)/archives/view-([0-9]+)-([0-9]+).html $1/plus/view.php?arcID=$2&pageno=$3 [I]
    #搜索偽靜態(tài)規(guī)則
    RewriteRule ^(.*)/search.html(?:(?.*))* $1/search.php?$2 [I]
    #TAG標(biāo)簽偽靜態(tài)規(guī)則
    RewriteRule ^(.*)/tags.html $1/tags.php [I]
    RewriteRule ^(.*)/tags/(.*)(?:(?.*))* $1/tags.php?/$2 [I]
    RewriteRule ^(.*)/tags/(.*)/(?:(?.*))* $1/tags.php?/$2/ [I]
    RewriteRule ^(.*)/tags/(.*)/([0-9])(?:(?.*))* $1/tags.php?/$2/$3 [I]
    RewriteRule ^(.*)/tags/(.*)/([0-9])/(?:(?.*))* $1/tags.php?/$2/$3/ [I]
    如果你的系統(tǒng)支持url重寫(xiě),到這里就可以用偽靜態(tài)訪問(wèn)了.
    第三步.更改重寫(xiě)的URL.
    如果用默認(rèn)的設(shè)置, 訪問(wèn)的URL是:
    代碼如下:
    http://www.XXXX.com/plus/view-131-1.html
    這樣的形色, 我們是可以更改這種樣式的.
    找到文件/include/helpers/channelunit.helper.php打開(kāi).
    可以看到有這樣的語(yǔ)句
    代碼如下:
    return $GLOBALS["cfg_plus_dir"]."/view-".$aid.'-1.html';
    這就是文章的url形色.
    $reurl = $GLOBALS['cfg_phpurl']."/list.php?tid=".$typeid;
    這是列表的重寫(xiě)url.
    可以使url更短一點(diǎn),完成可以寫(xiě)成:
    代碼如下:
    return "/view-".$aid.'-1.html';
    和
    $reurl = "/list-".$typeid.".html";
    這時(shí)重寫(xiě)規(guī)則也要更新.
    代碼如下:
    RewriteEngine On
    RewriteRule ^list-([0-9]+).html$ /plus/list.php?tid=$1
    RewriteRule ^list-([0-9]+)-([0-9]+)-([0-9]+).html$ /plus/list.php?tid=$1&totalresult=$2&PageNo=$3
    RewriteRule ^view-([0-9]+)-1.html$ /plus/view.php?arcID=$1
    RewriteRule ^view-([0-9]+)-([0-9]+).html$ /plus/view.php?aid=$1&pageno=$2
    更進(jìn)一步,還可以把view換成自己的任何詞語(yǔ),這也要把include/arc.archives.class.php文件中的view也一樣替換。
    發(fā)布選項(xiàng): 生成HTML 僅動(dòng)態(tài)瀏覽 發(fā)文章的時(shí)候選一下也不多事。為了以后升級(jí) 盡量減少修改文件。
    以下這沒(méi)有試,大家按需要測(cè)試吧~~
    修改數(shù)據(jù)庫(kù)
    將所有文檔設(shè)置為“僅動(dòng)態(tài)”,可以進(jìn)入數(shù)據(jù)庫(kù)管理中,執(zhí)行下面命令:
    代碼如下:
    update dede_archives set ismake=-1
    并將ismake的默認(rèn)值設(shè)置為 -1即動(dòng)態(tài)。
    將所有欄目設(shè)置為“使用動(dòng)態(tài)頁(yè)”,可以進(jìn)入數(shù)據(jù)庫(kù)管理中,執(zhí)行下面命令:
    代碼如下:
    update dede_arctype set isdefault=-1
    DedeCmsTAG標(biāo)簽偽靜態(tài)
    DedeCms默認(rèn)的TAG標(biāo)簽URL,形如/tags.php?/dedecms5.7/,非常之難看。打開(kāi)/include/taglib/tag.lib.php,找到lib_tag()函數(shù)下的:
    代碼如下:
    $row['link'] = $cfg_cmsurl."/tags.php?/".urlencode($row['keyword'])."/";
    替換為
    $row['link'] = $cfg_cmsurl."/tags/".urlencode($row['keyword'])."/";
    修改分頁(yè)代碼
    我們需要修改include/arc.taglist.class.php,將分頁(yè)函數(shù)替換為:
    代碼如下:
    /** * 獲取動(dòng)態(tài)的分頁(yè)列表
    *
    * @access public
    * @param int $list_len 列表寬度
    * @param string $listitem 列表樣式
    * @return string
    */
    function GetPageListDM($list_len,$listitem="info,index,end,pre,next,pageno")
    {
    $prepage="";
    $nextpage="";
    $prepagenum = $this->PageNo - 1;
    $nextpagenum = $this->PageNo + 1;
    if($list_len == "" || preg_match("/[^0-9]/", $list_len))
    {
    $list_len = 3;
    }
    $totalpage = $this->TotalPage;
    if($totalpage <= 1 && $this->TotalResult > 0)
    {
    return "<span>共1頁(yè)/".$this->TotalResult."條</span>";
    }
    if($this->TotalResult == 0)
    {
    return "<span>共0頁(yè)/".$this->TotalResult."條</span>";
    }
    $maininfo = "<span>共{$totalpage}頁(yè)/".$this->TotalResult."條</span>rn";
    $purl = $this->GetCurUrl();
    $basename = basename($purl);
    $tmpname = explode('.', $basename);
    $purl = str_replace($basename, '', $purl).urlencode($this->Tag);
    //var_dump($purl);exit;
    //$purl .= "?/".urlencode($this->Tag);
    //獲得上一頁(yè)和下一頁(yè)的鏈接
    if($this->PageNo != 1)
    {
    $prepage.="<li><a href='".$purl."-$prepagenum'.html>上一頁(yè)</a></li>rn";
    $indexpage="<li><a href='".$purl."-1.html'>首頁(yè)</a></li>rn";
    }
    else
    {
    $indexpage="<li><a>首頁(yè)</a></li>rn";
    }
    if($this->PageNo!=$totalpage && $totalpage>1)
    {
    $nextpage.="<li><a href='".$purl."-$nextpagenum.html'>下一頁(yè)</a></li>rn";
    $endpage="<li><a href='".$purl."-$totalpage.html'>末頁(yè)</a></li>rn";
    }
    else
    {
    $endpage="<li><a>末頁(yè)</a></li>rn";
    }
    //獲得數(shù)字鏈接
    $listdd="";
    $total_list = $list_len * 2 + 1;
    if($this->PageNo >= $total_list)
    {
    $j = $this->PageNo - $list_len;
    $total_list = $this->PageNo + $list_len;
    if($total_list > $totalpage)
    {
    $total_list = $totalpage;
    }
    }
    else
    {
    $j=1;
    if($total_list > $totalpage)
    {
    $total_list = $totalpage;
    }
    }
    for($j; $j<=$total_list; $j++)
    {
    if($j == $this->PageNo)
    {
    $listdd.= "<li><a>$j</a></li>rn";
    }
    else
    {
    $listdd.="<li><a href='".$purl."-$j.html'>".$j."</a></li>rn";
    }
    }
    $plist = '';
    if(preg_match('/info/i', $listitem))
    {
    $plist .= $maininfo.' ';
    }
    if(preg_match('/index/i', $listitem))
    {
    $plist .= $indexpage.' ';
    }
    if(preg_match('/pre/i', $listitem))
    {
    $plist .= $prepage.' ';
    }
    if(preg_match('/pageno/i', $listitem))
    {
    $plist .= $listdd.' ';
    }
    if(preg_match('/next/i', $listitem))
    {
    $plist .= $nextpage.' ';
    }
    if(preg_match('/end/i', $listitem))
    {
    $plist .= $endpage.' ';
    }
    return $plist;
    }