pasckr 发表于 2016-5-9 15:29:44

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=&quot;info,index,end,pre,next,pageno&quot;){$prepage=&quot;&quot;;$nextpage=&quot;&quot;;$prepagenum = $this->PageNo - 1;$nextpagenum = $this->PageNo + 1;if($list_len == &quot;&quot; || preg_match(&quot;/[^0-9]/&quot;, $list_len)){$list_len = 3;}$totalpage = $this->TotalPage;if($totalpage <= 1 && $this->TotalResult > 0){return &quot;<span class=&quot;pageinfo&quot;>共1页/&quot;.$this->TotalResult.&quot;条</span>&quot;;}if($this->TotalResult == 0){return &quot;<span class=&quot;pageinfo&quot;>共0页/&quot;.$this->TotalResult.&quot;条</span>&quot;;}$maininfo = &quot;<span class=&quot;pageinfo&quot;>共{$totalpage}页/&quot;.$this->TotalResult.&quot;条</span>rn&quot;;$purl = $this->GetCurUrl();$basename = basename($purl);$tmpname = explode('.', $basename);$purl = str_replace($basename, '', $purl).urlencode($this->Tag);//var_dump($purl);exit;//$purl .= &quot;?/&quot;.urlencode($this->Tag);//获得上一页和下一页的链接if($this->PageNo != 1){$prepage.=&quot;<li><a href='&quot;.$purl.&quot;-$prepagenum'.html>上一页</a></li>rn&quot;;$indexpage=&quot;<li><a href='&quot;.$purl.&quot;-1.html'>首页</a></li>rn&quot;;}else{$indexpage=&quot;<li><a>首页</a></li>rn&quot;;}if($this->PageNo!=$totalpage && $totalpage>1){$nextpage.=&quot;<li><a href='&quot;.$purl.&quot;-$nextpagenum.html'>下一页</a></li>rn&quot;;$endpage=&quot;<li><a href='&quot;.$purl.&quot;-$totalpage.html'>末页</a></li>rn&quot;;}else{$endpage=&quot;<li><a>末页</a></li>rn&quot;;}//获得数字链接$listdd=&quot;&quot;;$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.= &quot;<li class=&quot;thisclass&quot;><a>$j</a></li>rn&quot;;}else{$listdd.=&quot;<li><a href='&quot;.$purl.&quot;-$j.html'>&quot;.$j.&quot;</a></li>rn&quot;;}}$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=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?><configuration><system.webServer><rewrite><rules><rule name=&quot;weather1&quot; stopProcessing=&quot;true&quot;><match url=&quot;tags/([^-]+).html$&quot; ignoreCase=&quot;true&quot; /><conditions logicalGrouping=&quot;MatchAll&quot;><add input=&quot;{REQUEST_FILENAME}&quot; matchType=&quot;IsFile&quot; negate=&quot;true&quot; /><add input=&quot;{REQUEST_FILENAME}&quot; matchType=&quot;IsDirectory&quot; negate=&quot;true&quot; /></conditions><action type=&quot;Rewrite&quot; url=&quot;/tags.php?/{R:1}&quot; appendQueryString=&quot;false&quot; /></rule><rule name=&quot;weather2&quot; stopProcessing=&quot;true&quot;><match url=&quot;tags/([^-]+)-(+).html$&quot; ignoreCase=&quot;true&quot; /><conditions logicalGrouping=&quot;MatchAll&quot;><add input=&quot;{REQUEST_FILENAME}&quot; matchType=&quot;IsFile&quot; negate=&quot;true&quot; /><add input=&quot;{REQUEST_FILENAME}&quot; matchType=&quot;IsDirectory&quot; negate=&quot;true&quot; /></conditions><action type=&quot;Rewrite&quot; url=&quot;/tags.php?/{R:1}/{R:2}&quot; appendQueryString=&quot;false&quot; /></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)) $PageNo = intval($tags);下面哦:
function is_utf8($tag) { if (preg_match(&quot;/^([&quot;.chr(228).&quot;-&quot;.chr(233).&quot;]{1}[&quot;.chr(128).&quot;-&quot;.chr(191).&quot;]{1}[&quot;.chr(128).&quot;-&quot;.chr(191).&quot;]{1}){1}/&quot;,$tag) == true || preg_match(&quot;/([&quot;.chr(228).&quot;-&quot;.chr(233).&quot;]{1}[&quot;.chr(128).&quot;-&quot;.chr(191).&quot;]{1}[&quot;.chr(128).&quot;-&quot;.chr(191).&quot;]{1}){1}$/&quot;,$tag) == true || preg_match(&quot;/([&quot;.chr(228).&quot;-&quot;.chr(233).&quot;]{1}[&quot;.chr(128).&quot;-&quot;.chr(191).&quot;]{1}[&quot;.chr(128).&quot;-&quot;.chr(191).&quot;]{1}){2,}/&quot;,$tag) == true) { return true; } else { return false; } }  2.在第25行上面加入以下语句,也就是在$tag = FilterSearch(urldecode($tag));上面加入,记得这里是上面哦!
if(is_utf8($tag)==1) { $tag = iconv(&quot;utf-8&quot;,&quot;gbk&quot;,$tag); }  这个作用就是调用上面的函数判断编码 如果是 utf8则转为gbk;
  到此,tags伪静态问题全面完美解决!
页: [1]
查看完整版本: dedecms tags伪静态完美解决办法