帝国cms简单修改实现TAGS以TAGID的方式伪静态,注:此方法已经从帝国7.5原版测试通过!(本方法修改系统文件)
改后的地址形式如:/tags-100-0.html (数字100为TAG 的 ID)
第一步、打开/e/class/connect.php文件,找到
function eReturnRewriteTagsUrl($tagid,$tagname,$ecms=0){
global $public_r;
$tagname=urlencode($tagname);
if(empty($public_r[‘rewritetags’]))
{
$r[‘pageurl’]=$public_r[‘newsurl’].”e/tags/?tagname=”.$tagname;
$r[‘rewrite’]=0;
}
else
{
if($ecms==1)
{
$r[‘pageurl’]=$public_r[‘newsurl’].str_replace(array(‘[!–tagname–]’,'[!–page–]’),array($tagname,0),$public_r[‘rewritetags’]);
}
else
{
$r[‘pageurl’]=$public_r[‘newsurl’].str_replace(‘[!–tagname–]’,$tagname,$public_r[‘rewritetags’]);
}
$r[‘rewrite’]=1;
}
return $r;
}
此函数整个修改为:
function eReturnRewriteTagsUrl($tagid,$tagname,$ecms=0){
global $public_r,$empire,$dbtbpre;
if(!$tagid){
$tagname=RepPostVar($tagname);
if(!$tagname)
{
$r['pageurl']=$public_r['newsurl'];
$r['rewrite']=0;
return $r;
}
$tagr=$empire->fetch1("select tagid,num from {$dbtbpre}enewstags where tagname='$tagname' limit 1");
if(!$tagr['tagid'])
{
$r['pageurl']=$public_r['newsurl'];
$r['rewrite']=0;
return $r;
}
$tagid=$tagr['tagid'];
}
if(empty($public_r['rewritetags']))
{
$r['pageurl']=$public_r['newsurl']."e/tags/?tagid=".$tagid;
$r['rewrite']=0;
}
else
{
if($ecms==1)
{
$r['pageurl']=$public_r['newsurl'].str_replace(array('[!–tagname–]','[!–page–]'),array($tagid,0),$public_r['rewritetags']);
}
else
{
$r['pageurl']=$public_r['newsurl'].str_replace('[!–tagname–]',$tagid,$public_r['rewritetags']);
}
$r['rewrite']=1;
}
return $r;
}
之后找到下面代码:
//伪静态替换分页号
function eReturnRewritePageLink($r,$page){
//动静
$truepage=$page+1;
if($r['repagenum']&&$truepage<=$r['repagenum'])
{
//文件名
if(empty($r['dofile']))
{
$r['dofile']='index';
}
$url=$r['dolink'].$r['dofile'].($truepage==1?'':'_'.$truepage).$r['dotype'];
return $url;
}
if($r['rewrite']==1)
{
$url=str_replace('[!--page--]',$page,$r['pageurl']);
}
else
{
$url=$r['pageurl'].'&page='.$page;
}
return $url;
}
修改为:
//伪静态替换分页号
function eReturnRewritePageLink($r,$page){
//动静
$truepage=$page+1;
if($r['repagenum']&&$truepage<=$r['repagenum'])
{
//文件名
if(empty($r['dofile']))
{
$r['dofile']='index';
}
$url=$r['dolink'].$r['dofile'].($truepage==1?'':'_'.$truepage).$r['dotype'];
return $url;
}
if($r['rewrite']==1)
{
$url=str_replace('[!–page–]',$page,$r['pageurl']);
}
else
{
$url=$r['pageurl'].'&page='.$page;
}
return $url;
}
第二步、打开/e/tags/index.php文件
找到
if(!empty($public_r[‘rewritetags’])&&empty($add)&&($search==’&tagname=’.$tagname.’&line=’.$public_r[‘tagslistnum’].’&tempid=’.$public_r[‘tagstempid’]||$search==’&tagid=’.$tagid.’&line=’.$public_r[‘tagslistnum’].’&tempid=’.$public_r[‘tagstempid’])&&!$myorder)
{
//伪静态
$pagefunr=eReturnRewriteTagsUrl($tagid,$tagr[‘tagid’]?$tagname:’etagid’.$tagid,0);
$pagefunr[‘repagenum’]=0;
//分页
if($pagefunr[‘rewrite’]==1)
{
$listpage=InfoUsePage($num,$line,$page_line,$start,$page,$search,$pagefunr);
}
else
{
$listpage=page1($num,$line,$page_line,$start,$page,$search);
}
}
else
{
$listpage=page1($num,$line,$page_line,$start,$page,$search);//分页
}
修改为:
/*
if(!empty($public_r['rewritetags'])&&empty($add)&&($search=='&tagname='.$tagname.'&line='.$public_r['tagslistnum'].'&tempid='.$public_r['tagstempid']||$search=='&tagid='.$tagid.'&line='.$public_r['tagslistnum'].'&tempid='.$public_r['tagstempid'])&&!$myorder)
{
*/
//伪静态
$pagefunr=eReturnRewriteTagsUrl($tagid,$tagname,0);
$pagefunr['repagenum']=0;
//分页
if($pagefunr['rewrite']==1)
{
$listpage=InfoUsePage($num,$line,$page_line,$start,$page,$search,$pagefunr);
}
else
{
$listpage=page1($num,$line,$page_line,$start,$page,$search);
}
/*
}
else
{
$listpage=page1($num,$line,$page_line,$start,$page,$search);//分页
}
*/
第三步:后台设置tag伪静态
按照默认,设置成:tags-[!–tagname–]-[!–page–].html 即可。
第四步:服务器伪静态规则
apache的伪静态规则如下,其它类型服务器请对照此自行修改:
RewriteRule ^tags-(.*)-(.*)$ e/tags/index.php?tagid=$1&page=$2
nginx下的伪静态规则如下:
rewrite ^([^.]*)/tags-(.+?)-(.+?).html$ $1/e/tags/index.php?tagid=$2&page=$3 last;