DedeCMS系统TAG标签伪静态设置

DedeCMS的系统TAGS确实是一个非常好的功能,通过关键词链接可以快速寻找到相关内容,不过很多人希望能够将TAGS静态化这样更加利于SEO,CIT.CN也是对此进行了优化和调整,只不过cit小虫觉得这种更新内容比较频繁的列表最好采用伪静态的方式,这里就分享下技巧。

1.修改前台显示链接

我们这里达到的效果就是使原来/tags.php?keywors更改为/tags/keywords.html。

这里主要修改下调用的标签,在includetaglibtag.lib.php中,在87行找到

1 $row['link'] = $cfg_cmsurl."/tags?".urlencode($row['keyword']);

将其改为:

1 $row['link'] = $cfg_cmsurl."/tags/".urlencode($row['keyword']).".html";

2.修改分页代码

我们需要修改include/arc.taglist.class.php,将分页函数替换为:

001 /**
002      *  获取动态的分页列表
003      *
004      * @access    public
005      * @param     int  $list_len  列表宽度
006      * @param     string  $listitem  列表样式
007      * @return    string
008      */
009     function GetPageListDM($list_len,$listitem="info,index,end,pre,next,pageno")
010     {
011         $prepage="";
012         $nextpage="";
013         $prepagenum = $this->PageNo - 1;
014         $nextpagenum = $this->PageNo + 1;
015         if($list_len == "" || preg_match("/[^0-9]/", $list_len))
016         {
017             $list_len = 3;
018         }
019         $totalpage = $this->TotalPage;
020         if($totalpage <= 1 && $this->TotalResult > 0)
021         {
022             return "<span class="pageinfo">共1页/".$this->TotalResult."条</span>";
023         }
024         if($this->TotalResult == 0)
025         {
026             return "<span class="pageinfo">共0页/".$this->TotalResult."条</span>";
027         }
028         $maininfo = "<span class="pageinfo">共{$totalpage}页/".$this->TotalResult."条</span>rn";
029         $purl = $this->GetCurUrl();
030         $basename basename($purl);
031         $tmpname = explode('.', $basename);
032         
033         $purl = str_replace($basename'', $purl).urlencode($this->Tag);
034         //var_dump($purl);exit;
035         //$purl .= "?/".urlencode($this->Tag);
036
037         //获得上一页和下一页的链接
038         if($this->PageNo != 1)
039         {
040             $prepage.="<li><a href='".$purl."-$prepagenum'.html>上一页</a></li>rn";
041             $indexpage="<li><a href='".$purl."-1.html'>首页</a></li>rn";
042         }
043         else
044         {
045             $indexpage="<li><a>首页</a></li>rn";
046         }
047         if($this->PageNo!=$totalpage && $totalpage>1)
048         {
049             $nextpage.="<li><a href='".$purl."-$nextpagenum.html'>下一页</a></li>rn";
050             $endpage="<li><a href='".$purl."-$totalpage.html'>末页</a></li>rn";
051         }
052         else
053         {
054             $endpage="<li><a>末页</a></li>rn";
055         }
056
057         //获得数字链接
058         $listdd="";
059         $total_list = $list_len * 2 + 1;
060         if($this->PageNo >= $total_list)
061         {
062             $j = $this->PageNo - $list_len;
063             $total_list = $this->PageNo + $list_len;
064             if($total_list > $totalpage)
065             {
066                 $total_list = $totalpage;
067             }
068         }
069         else
070         {
071             $j=1;
072             if($total_list > $totalpage)
073             {
074                 $total_list = $totalpage;
075             }
076         }
077         for($j; $j<=$total_list; $j++)
078         {
079             if($j == $this->PageNo)
080             {
081                 $listdd.= "<li class="thisclass"><a>$j</a></li>rn";
082             }
083             else
084             {
085                 $listdd.="<li><a href='".$purl."-$j.html'>".$j."</a></li>rn";
086             }
087         }
088         $plist  =  '';
089         if(preg_match('/info/i', $listitem))
090         {
091             $plist .= $maininfo.' ';
092         }
093         if(preg_match('/index/i', $listitem))
094         {
095             $plist .= $indexpage.' ';
096         }
097         if(preg_match('/pre/i', $listitem))
098         {
099             $plist .= $prepage.' ';
100         }
101         if(preg_match('/pageno/i', $listitem))
102         {
103             $plist .= $listdd.' ';
104         }
105         if(preg_match('/next/i', $listitem))
106         {
107             $plist .= $nextpage.' ';
108         }
109         if(preg_match('/end/i', $listitem))
110         {
111             $plist .= $endpage.' ';
112         }
113         return $plist;
114     }

3.设置伪静态规则

我们这里以iis7为例子,设置以下规则:

 

01 <?xml version="1.0" encoding="UTF-8"?>
02
03 <configuration>
04
05     <system.webServer>
06
07         <rewrite>
08
09             <rules>
10
11                 <rule name="weather1" stopProcessing="true">
12
13                     <match url="tags/([^-]+).html$" ignoreCase="true" />
14
15                     <conditions logicalGrouping="MatchAll">
16
17                         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
18
19                         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
20
21                     </conditions>
22
23                     <action type="Rewrite" url="/tags.php?/{R:1}" appendQueryString="false" />
24
25                 </rule>
26
27                 <rule name="weather2" stopProcessing="true">
28
29                     <match url="tags/([^-]+)-([0-9]+).html$" ignoreCase="true" />
30
31                     <conditions logicalGrouping="MatchAll">
32
33                         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
34
35                         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
36
37                     </conditions>
38
39                     <action type="Rewrite" url="/tags.php?/{R:1}/{R:2}" appendQueryString="false" />
40
41                 </rule>
42
43             </rules>
44
45         </rewrite>
46
47     </system.webServer>
48
49 </configuration>

可以直接保存为web.config放在站点根目录。

4.重新生成html页面

这个操作就不用说了,全部重新生成下,至此全部修改完毕。

5.预览查看显示结果

至此,我们已经完成了所有的设置


爱搜源码 » DedeCMS系统TAG标签伪静态设置

发表评论

发表评论