天天看點

[PHP]DEDECMS全站僞靜态詳細教程(首頁、清單、文章頁)

本人比較懶,相信不少朋友也是,懶得每次去生成dedecms的HTML,同時為了現已不太有效的僞靜态優化,是以還是搞搞僞靜态吧。

本dedecms全站僞靜态教程分為五部分,包括“Apache設定、.htaccess檔案設定、首頁僞靜态、清單頁僞靜态、文章頁僞靜态”。

用4.0測試OK,5.X沒測。

一、Apache檔案設定

這是重頭戲,以前用本地測試時因 httpd.conf 檔案沒設定好,搞得焦頭爛額。

1、如果是虛拟主機,一般 apache 的 LoadModule rewrite_module modules/mod_rewrite.so 是開啟的,請咨詢你的主機提供商以确認是否支援僞靜态。

2、如果是自己的伺服器或本地機器,請按以下設定:

關閉 apache 服務。

打開 httpd.conf 檔案(一般放在apache安裝目錄的conf目錄下)把 #LoadModule rewrite_module modules/mod_rewrite.so 前的 # 号去掉,代表開啟 rewrite 規則。

搜尋 “AllowOverride None”(不包括引号,下同) ,有多個,全部替換為 “AllowOverride All”。

開啟 apache 服務。

二、.htaccess檔案設定

在網站根目錄建一 .htaccess 檔案,内容為:

RewriteEngine On

RewriteBase /

RewriteRule ^(.*)index\.html$ $1/index.php

RewriteRule ^(.*)list-([0-9]+)\.html$ $1/plus/list.php?tid=$2

RewriteRule ^(.*)list-([0-9]+)-([0-9]+)\.html$ $1/plus/list.php?typeid=$2&PageNo=$3

RewriteRule ^(.*)view-([0-9]+).html$ $1/plus/view.php?aid=$2 

RewriteRule ^(.*)view-([0-9]+)-([0-9]+).html$ $1/plus/view.php?aid=$2&pageno=$3

三、dedecms首頁僞靜态

不要更新首頁html就行。如果已更新,請删除index.html即可。

四、dedecms清單頁僞靜态

1、打開 /include/inc_arclist_view.php 找到

//---------------------------------

//擷取動态的分頁清單

把它下面的函數改成以下的:

function GetPageListDM($list_len,$listitem="index,end,pre,next,pageno")

    {

        $prepage="";

        $nextpage="";

        $prepagenum = $this->PageNo-1;

        $nextpagenum = $this->PageNo+1;

        if($list_len==""||ereg("[^0-9]",$list_len)) $list_len=3;

        $totalpage = ceil($this->TotalResult/$this->PageSize);

        if($totalpage<=1 && $this->TotalResult>0) return "共1頁/".$this->TotalResult."條記錄"; 

        if($this->TotalResult == 0) return "共0頁".$this->TotalResult."條記錄"; 

        $maininfo = "共{$totalpage}頁/".$this->TotalResult."條記錄";

        $purl = $this->GetCurUrl();

        $geturl = "typeid=".$this->TypeID."&TotalResult=".$this->TotalResult."&";

        $gettypeid =$this->TypeID."-";

        //$hidenform = "<input type='hidden' name='typeid' value='".$this->TypeID."'>";

        //$hidenform .= "<input type='hidden' name='TotalResult' value='".$this->TotalResult."'>";

        $purl .= "?".$geturl;

        //獲得上一頁和下一頁的連結

        if($this->PageNo != 1){

            $prepage.="<a href='list-".$gettypeid."$prepagenum.html'>上一頁</a>";

            $indexpage="<a href='list-".$gettypeid."1.html'>首頁</a>";

        }

        else{

            $indexpage="首頁";

        }    

        if($this->PageNo!=$totalpage && $totalpage>1){

            $nextpage.="<a href='list-".$gettypeid."$nextpagenum.html'>下一頁</a>";

            $endpage="<a href='list-".$gettypeid."$totalpage.html'>末頁</a>";

            $endpage="末頁";

        //獲得數字連結

        $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++){

          $listdd.="<a href='list-".$gettypeid."$j.html'>".$j."</a>";

        $plist .= $maininfo.$indexpage.$prepage.$listdd.$nextpage.$endpage;

        return $plist;

    }

2、打開 /include/inc_channel_unit_functions.php 查找

    $reurl = $GLOBALS["cfg_plus_dir"]."/list.php?tid=".$typeid;

改成

    $reurl = "/list-".$typeid.".html"; //清單頁僞靜态

五、dedecms文章頁僞靜态

1、打開 /include/inc_archives_view.php ,有兩處修改的地方,

1.1 找到:

        //------------------------

         //獲得動态頁面分頁清單

         //------------------------

   function GetPagebreakDM($totalPage,$nowPage,$aid)

        {

                if($totalPage==1){ return ""; }

                $PageList = "共".$totalPage."頁: ";

                $nPage = $nowPage-1;

                $lPage = $nowPage+1;

                if($nowPage==1) $PageList.="上一頁 ";

                else{

                  if($nPage==1) $PageList.="<a href='view.php?aid=$aid'>上一頁</a> ";

                  else $PageList.="<a href='view.php?aid=$aid&pageno=$nPage'>上一頁</a> ";

                }

                for($i=1;$i<=$totalPage;$i++)

                {

                        if($i==1){

                          if($nowPage!=1) $PageList.="<a href='view.php?aid=$aid'>[1]</a> ";

                          else $PageList.="1 ";

                        }else{

                          $n = $i;

                          if($nowPage!=$i) $PageList.="<a href='view.php?aid=$aid&pageno=$i'>[".$n."]</a> ";

                          else $PageList.="$n ";

                        }

                if($lPage <= $totalPage) $PageList.="<a href='view.php?aid=$aid&pageno=$lPage'>下一頁</a> ";

                else $PageList.= "下一頁 ";

                return $PageList;

修改為:

//獲得僞靜态頁面分頁清單

                  if($nPage==1) $PageList.="<a href='view-$aid'>上一頁</a> ";

                  else $PageList.="<a href='view-$aid-$nPage.html'>上一頁</a> ";

                          if($nowPage!=1) $PageList.="<a href='view-$aid'>[1]</a> ";

                          if($nowPage!=$i) $PageList.="<a href='view-$aid-$i.html'>[".$n."]</a> ";

                if($lPage <= $totalPage) $PageList.="<a href='view-$aid-$lPage.html'>下一頁</a> ";

        }  

1.2 找到:

        //-------------------------

        //獲得動态頁面小标題

   function GetPageTitlesDM($styleName,$pageNo)

                if($this->TotalPage==1){ return ""; }

                if(count($this->SplitTitles)==0){ return ""; }

                $i=1;

                $aid = $this->ArcID;

                if($styleName=='link')

                        $revalue = "";

                  foreach($this->SplitTitles as $k=>$v){

                           if($i==1) $revalue .= "<a href='view.php?aid=$aid&pageno=$i'>$v</a> ";

                     else{

                              if($pageNo==$i) $revalue .= " $v ";

                              else $revalue .= "<a href='view.php?aid=$aid&pageno=$i'>$v</a> ";

                     }

                     $i++;

                  }

          }else

          {

                  $revalue = "<select id='dedepagetitles' onchange='location.href=this.options[this.selectedIndex].value;'>";

                        foreach($this->SplitTitles as $k=>$v){

                           if($i==1) $revalue .= "<option value='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$i'& gt;{$i}、{$v}</option>";

                              if($pageNo==$i) $revalue .= "<option value='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$i' selected>{$i}、{$v}</option>";

                              else $revalue .= "<option value='".$this->Fields['phpurl']."/view.php?aid=$aid&pageno=$i'& gt;{$i}、{$v}</option>";

                  $revalue .= "</select>";

          }

                return $revalue;

   //擷取僞靜态頁面小标題

                           if($i==1) $revalue .= "<a href='view-$aid-$i.html'>$v</a> ";

                              else $revalue .= "<a href='view-$aid-$i.html'>$v</a> ";

                           if($i==1) $revalue .= "<option value='".$this->Fields['phpurl']."/view-$aid-$i.html'>{$i}、{$v}& lt;/option>";

                              if($pageNo==$i) $revalue .= "<option value='".$this->Fields['phpurl']."/view-$aid-$i.html' selected>{$i}、{$v}</option>";

                              else $revalue .= "<option value='".$this->Fields['phpurl']."/view-$aid-$i'>{$i}、{$v}< /option>";

    return $GLOBALS['cfg_plus_dir']."/view.php?aid=$aid";

    return "/view-$aid.html";//文章頁僞靜态

六、完工。把欄目和文章都改為動态,重新整理,dedecms全站僞靜态成功。

把欄目和文章批量修改為動态的SQL語句:

update dede_arctype set isdefault=-1;

update dede_archives set ismake=-1;

更新:

DEDECMS搜尋的僞靜态在 .htaccess 檔案裡加入如下兩句即可:

RewriteRule ^(.*)/search/([^/]*)$   $1/plus/search\.php\?keyword=$2 

RewriteRule ^(.*)/search/([^/]*)/(\d)$   $1/plus/search\.php\?keyword=$2&PageNo=$3

本文轉自黃聰部落格園部落格,原文連結:http://www.cnblogs.com/huangcong/archive/2011/04/22/2025027.html,如需轉載請自行聯系原作者