dedecms tags偽靜態(tài)完美解決辦法

字號(hào):


    用dedecms 系統(tǒng)做網(wǎng)站的朋友特別多,dedecms功能強(qiáng)大,除了安全是一個(gè)問(wèn)題外,tags標(biāo)簽靜態(tài)化問(wèn)題困擾很多朋友,湖哥為了解決一個(gè)網(wǎng)站的tags標(biāo)簽靜態(tài)化問(wèn)題找了很多文章,也試了很多次,終于在今天解決了這個(gè)問(wèn)題:
    1.dedecms版本  5.7 sp1 GBK
    2.服務(wù)器:windows 2008 iis7
    話(huà)不多說(shuō),開(kāi)始!
    目標(biāo):我們要使原來(lái)tags.php?/3qshop/  變動(dòng)為/tags/3qshop.html 并且為偽靜態(tài),為什么要為偽靜態(tài)?因?yàn)槲覀兊年P(guān)鍵詞(tags)太多,比真正靜態(tài)節(jié)省空間。
    那么我們要做如下工作,記得一步一步來(lái)哦!
    第1步:
    首先找到/include/taglib/tag.lib.php中,在87行找到
    $row['link'] = $cfg_cmsurl."/tags?".urlencode($row['keyword']);
    將其修改為:
    $row['link'] = $cfg_cmsurl."/tags/".urlencode($row['keyword']).".html";
    第2步:
    修改分頁(yè)代碼部分
    修改include/arc.taglist.class.php,找到分頁(yè)函數(shù),將其更換為:
    注意:從429行  ---->541行  用以下內(nèi)容替換!
    (提示:網(wǎng)上有文章中講的以下代碼中的"pageinfo"是錯(cuò)誤的,應(yīng)該為"pageinfo",不然會(huì)有錯(cuò)誤提示哦!已經(jīng)代碼測(cè)試OK?。?BR>    /** * 獲取動(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;
    }
    第3步:
    設(shè)置偽靜態(tài)規(guī)則:
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
    <system.webServer>
    <rewrite>
    <rules>
    <rule name="weather1" stopProcessing="true">
    <match url="tags/([^-]+).html$" ignoreCase="true" />
    <conditions logicalGrouping="MatchAll">
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="/tags.php?/{R:1}" appendQueryString="false" />
    </rule>
    <rule name="weather2" stopProcessing="true">
    <match url="tags/([^-]+)-([0-9]+).html$" ignoreCase="true" />
    <conditions logicalGrouping="MatchAll">
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="/tags.php?/{R:1}/{R:2}" appendQueryString="false" />
    </rule>
    </rules>
    </rewrite>
    </system.webServer>
    </configuration>
    把以上內(nèi)容保存為:web.config  放到網(wǎng)站根目錄!
    第4步:
    生成文章,瀏覽!大功告成?錯(cuò),有可能你會(huì)出現(xiàn)以下錯(cuò)誤!
    系統(tǒng)無(wú)此標(biāo)簽,可能已經(jīng)移除!
    你還可以嘗試通過(guò)搜索程序去搜索這個(gè)關(guān)鍵字:前往搜索>>
    如果你的瀏覽器沒(méi)反應(yīng),請(qǐng)點(diǎn)擊這里...
    解決辦法如下:
    在網(wǎng)站根目錄下找到tags.php 此文件,將以下代碼替換掉:
    $tag = trim($_SERVER['QUERY_STRING']);
    換成
    $tag = strtolower(trim($_SERVER['QUERY_STRING']));
    出現(xiàn)這個(gè)問(wèn)題的原因是IIS偽靜態(tài)中文轉(zhuǎn)碼為UTF8,解決方法就是在tags.php中加入判斷UTF8編碼的語(yǔ)句,如果是則轉(zhuǎn)換為GBK,這樣就可以解決了
    方法:
    1.把以下代碼加入到根目錄下tags.php中的18行下面,也就是if(isset($tags[2])) $PageNo = intval($tags[2]);下面哦:
    function is_utf8($tag)
    {
    if (preg_match("/^([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}/",$tag) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}$/",$tag) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){2,}/",$tag) == true)
    {
    return true;
    }
    else
    {
    return false;
    }
    }
    2.在第25行上面加入以下語(yǔ)句,也就是在$tag = FilterSearch(urldecode($tag));上面加入,記得這里是上面哦!
    if(is_utf8($tag)==1) { $tag = iconv("utf-8","gbk",$tag); }
    這個(gè)作用就是調(diào)用上面的函數(shù)判斷編碼 如果是 utf8則轉(zhuǎn)為gbk;
    到此,tags偽靜態(tài)問(wèn)題全面完美解決!