说起dedecms的tag标签伪静态化,很多刚接触的小伙伴都很头疼吧,网上找了一大堆资料,实现是可以,但总是不可避免的有一些小错误,导致无法完美运行,今天西宁网站建设思帽网络为大家带来全网最完美无错的tag标签伪静态方法,快来记笔记吧!
第一步,和你在网上找到的方法一样,找到根目录下面的tag.php中的这段代码,如下:
将其替换成如下代码:
//伪静态化
$tagid = (isset($tagid) && is_numeric($tagid)) ? $tagid : 0;
$PageNo = (isset($PageNo) && is_numeric($PageNo)) ? $PageNo : 1;
if ($tagid =="0") {
$dlist = new TagList($tag, 'tag.htm');
$dlist->Display();}
else{$row = $dsql->GetOne("SELECT tag FROM `dede_tagindex` WHERE id ={$tagid}");
if (!is_array($row)) {ShowMsg('系统无此tag', '-1');
exit();}
$tag = FilterSearch($row['tag']);
$dlist = new TagList($tag, 'taglist.htm');
$dlist->Display();}
exit();
第二步,在include\taglib中找到tag.lib.php文件的$row['link'] = $cfg_cmsurl."/tags.php?/".urlencode($row['keyword'])."/";(大约在88行左右),替换成 $row['link'] = "/tags/{$row['id']}.html";
第三步,就是修改我们的分页代码,找到include文件下的arc.taglist.class.php中的GetPageListDM函数(重点:区别于网上其它方法),请用以下代码替换:
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";
$basename = $this->TagInfos;
$purl = $basename['id'];
//获得上一页和下一页的链接
if($this->PageNo != 1)
{
$prepage.="<li><a href='".$purl."-$prepagenum.html'>上一页</a></li>\r\n";
$indexpage="<li><a href='".$purl."-1.html'>首页</a></li>\r\n";
}
else
{
$indexpage="<li><a>首页</a></li>\r\n";
}
if($this->PageNo!=$totalpage && $totalpage>1)
{
$nextpage.="<li><a href='".$purl."-$nextpagenum.html'>下一页</a></li>\r\n";
$endpage="<li><a href='".$purl."-$totalpage.html'>末页</a></li>\r\n";
}
else
{
$endpage="<li><a>末页</a></li>\r\n";
}
//获得数字链接
$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.html'>".$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;
}
第四步,设置Apache的.htaccess中的规则(完美解决),如下:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^tags/([0-9]+)-([0-9]+).html$ tags.php?tagid=$1&PageNo=$2 [L]
RewriteRule ^tags/([0-9]+).html$ tags.php?tagid=$1 [L]
</IfModule>
第五步,设置IIs的web.config中的规则(完美解决),如下:
<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?tagid={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?tagid={R:1}&PageNo={R:2}" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
好了,以上就是思帽网络为广大网站建设者提供的最完美解决方案,如有任何交流都可以联系我们,请时刻关注我们的官网(http://www.qhsimao.com)动态!