POST TIME:2020-04-03 15:55
1.dedecms版本 5.7 sp1 GBK
2.服務器:windows 2008 iis7
話不多說,開始!
目標:我們要使原來tags.php?/3qshop/ 變動為/tags/3qshop.html 并且為偽靜態,為什么要為偽靜態?因為我們的關鍵詞(tags)太多,比真正靜態節省空間。
那么我們要做如下工作,記得一步一步來哦!
第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步:
修改分頁代碼部分
修改include/arc.taglist.class.php,找到分頁函數,將其更換為:
注意:從429行 ---->541行 用以下內容替換!
(提示:網上有文章中講的以下代碼中的"pageinfo"是錯誤的,應該為"pageinfo",不然會有錯誤提示哦!已經代碼測試OK!)
/** * 獲取動態的分頁列表 * * @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 class="pageinfo">共1頁/".$this->TotalResult."條</span>"; } if($this->TotalResult == 0) { return "<span class="pageinfo">共0頁/".$this->TotalResult."條</span>"; } $maininfo = "<span class="pageinfo">共{$totalpage}頁/".$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); //獲得上一頁和下一頁的鏈接 if($this->PageNo != 1) { $prepage.="<li><a href='".$purl."-$prepagenum'.html>上一頁</a></li>rn"; $indexpage="<li><a href='".$purl."-1.html'>首頁</a></li>rn"; } else { $indexpage="<li><a>首頁</a></li>rn"; } if($this->PageNo!=$totalpage && $totalpage>1) { $nextpage.="<li><a href='".$purl."-$nextpagenum.html'>下一頁</a></li>rn"; $endpage="<li><a href='".$purl."-$totalpage.html'>末頁</a></li>rn"; } else { $endpage="<li><a>末頁</a></li>rn"; } //獲得數字鏈接 $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 class="thisclass"><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步:設置偽靜態規則:
<?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>把以上內容保存為:web.config 放到網站根目錄!
第4步:
生成文章,瀏覽!大功告成?錯,有可能你會出現以下錯誤!
系統無此標簽,可能已經移除!
你還可以嘗試通過搜索程序去搜索這個關鍵字:前往搜索>>
如果你的瀏覽器沒反應,請點擊這里...
解決辦法如下:
在網站根目錄下找到tags.php 此文件,將以下代碼替換掉:
$tag = trim($_SERVER['QUERY_STRING']);換成
$tag = strtolower(trim($_SERVER['QUERY_STRING']));
出現這個問題的原因是IIS偽靜態中文轉碼為UTF8,解決方法就是在tags.php中加入判斷UTF8編碼的語句,如果是則轉換為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行上面加入以下語句,也就是在$tag = FilterSearch(urldecode($tag));上面加入,記得這里是上面哦!
if(is_utf8($tag)==1) { $tag = iconv("utf-8","gbk",$tag); }這個作用就是調用上面的函數判斷編碼 如果是 utf8則轉為gbk;
到此,tags偽靜態問題全面完美解決!