
| 歡迎訪問全國企業(yè)網(wǎng)站設計NO.1網(wǎng)站開發(fā)商平臺 | 付款方式 |
POST TIME:2020-10-09
dedecms作為當前一款使用非常廣泛的建站系統(tǒng),如何更好的優(yōu)化成為每個站長的第一件大事,首先我們要考慮的是Dedecms的url規(guī)則,而在url規(guī)則中,tag標簽是最差的,建議大家使用偽靜態(tài),但是網(wǎng)上的教程都不太全面,本文就收集整理了最新的dedecms5.7標簽tag完善偽靜態(tài)教程,歡迎大家閱讀。
1.dedecms版本 5.7 sp1 GBK
| 軟件名稱: | DedeCMS |
| 軟件版本: | v5.7 sp1 GBK |
| 軟件大小: | 7.1MB |
| 軟件授權: | 免費版本 |
| 適用平臺: | Win9X Win2000 WinXP Win2003 Vista Win7 |
| 下載地址: | http://www.dede58.com/down/html/30167.html |
2.服務器:windows 2008 iis7
話不多說,開始!
目標:我們要使原來tags.php?/veryhuo/ 變動為/tags/veryhuo.html 并且為偽靜態(tài),為什么要為偽靜態(tài)?因為我們的關鍵詞(tags)太多,比真正靜態(tài)節(jié)省空間。
那么我們要做如下工作,記得一步一步來哦!
第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,找到分頁函數(shù),將其更換為:
注意:從429行 ---->541行 用以下內(nèi)容替換!
(提示:網(wǎng)上有文章中講的以下代碼中的"pageinfo"是錯誤的,應該為\"pageinfo\",不然會有錯誤提示哦!已經(jīng)代碼測試OK!)
/**
* 獲取動態(tài)的分頁列表
*
* @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>\r\n";
$purl = $this->GetCurUrl();
$purl .= "?/".urlencode($this->Tag);
|
//獲得上一頁和下一頁的鏈接
if($this->PageNo != 1)
{
$prepage.="<li><a href='".$purl."/$prepagenum/'>上一頁</a></li>\r\n";
$indexpage="<li><a href='".$purl."/1/'>首頁</a></li>\r\n";
}
else
{
$indexpage="<li><a>首頁</a></li>\r\n";
}
if($this->PageNo!=$totalpage && $totalpage>1)
{
$nextpage.="<li><a href='".$purl."/$nextpagenum/'>下一頁</a></li>\r\n";
$endpage="<li><a href='".$purl."/$totalpage/'>末頁</a></li>\r\n";
}
else
{
$endpage="<li><a>末頁</a></li>\r\n";
}
//獲得數(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 class=\"thisclass\"><a>$j</a></li>\r\n";
}
else
{
$listdd.="<li><a href='".$purl."/$j/'>".$j."</a></li>\r\n";
}
}
$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步:
設置偽靜態(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步:
生成文章,瀏覽!大功告成?錯,有可能你會出現(xiàn)發(fā)下錯誤!
系統(tǒng)無此標簽,可能已經(jīng)移除!
你還可以嘗試通過搜索程序去搜索這個關鍵字:前往搜索>>
如果你的瀏覽器沒反應,請點擊這里...
解決辦法如下:
在網(wǎng)站根目錄下找到tags.php 此文件,將以下代碼替換掉:
$tag = trim($_SERVER['QUERY_STRING']);
換成
$tag = strtolower(trim($_SERVER['QUERY_STRING']));
出現(xiàn)這個問題的原因是IIS偽靜態(tài)中文轉碼為UTF8,解決方法就是在tags.php中加入判斷UTF8編碼的語句,如果是則轉換為GBK,這樣就可以解決了
方法:
1.把以下代碼加入到根目錄下tags.php中的18行下面,記得是下面哦:
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); }
這個作用就是調(diào)用上面的函數(shù)判斷編碼 如果是 utf8則轉為gbk;
到此,tags偽靜態(tài)問題全面完美解決!
巨號網(wǎng)網(wǎng)站開發(fā)部為全國企業(yè)提供網(wǎng)頁設計和專業(yè)的公司網(wǎng)站制作等相關建站服務,并提供24小時企業(yè)網(wǎng)站設計咨詢!