dedecms 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 "共1页/".$this->TotalResult."条"; } if($this->TotalResult == 0) { return "共0页/".$this->TotalResult."条"; } $maininfo = "共{$totalpage}页/".$this->TotalResult."条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.="设置伪静态规则:
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>把以上内容保存为:web.config 放到网站根目录!
第4步:
生成文章,浏览!大功告成?错,有可能你会出现以下错误!
系统无此标签,可能已经移除!
你还可以尝试通过搜索程序去搜索这个关键字:前往搜索>>
如果你的浏览器没反应,请点击这里...
解决办法如下:
#p#分页标题#e#在网站根目录下找到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; } } #p#分页标题#e#2.在第25行上面加入以下语句,也就是在$tag = FilterSearch(urldecode($tag));上面加入,记得这里是上面哦!
if(is_utf8($tag)==1) { $tag = iconv("utf-8","gbk",$tag); }这个作用就是调用上面的函数判断编码 如果是 utf8则转为gbk;
到此,tags伪静态问题全面完美解决!
本文手机访问二维码
☉本站的源码不会像其它下载站一样植入大量的广告。
☉本站只提供精品织梦源码,源码在于可用,不在多!!希望在这里找到你合适的。
☉本站提供的整站织梦程序,均带数据及演示地址。可以在任一源码详情页查看演示地址
☉本站所有资源(包括源码、模板、素材、特效等)仅供学习与参考,请勿用于商业用途。
☉如有其他问题,请加网站客服QQ(971977809)进行交流