最近访客
百度未收录

dedecms tags伪静态完美解决办法

用dedecms 系统做网站的朋友特别多,dedecms功能强大,除了安全是一个问题外,tags标签静态化问题困扰很多朋友,湖哥为了解决一个网站的tags标签静态化问题找了很多文章,也试了很多次,终于在今天解决了这个问题:

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
quot; 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
quot; 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伪静态问题全面完美解决!

温馨提示: 本文最后更新于2022/10/20 02:17:47。若文章内容或图片失效,请 留言联系站长反馈!
!
也想出现在这里? 联系我们
创意广告
© 版权声明
THE END
点赞0赞赏 分享
评论 抢沙发

请登录后发表评论

    请登录后查看评论内容