首先在dede后台开启伪静态(开启的方法在系统参数-核心设置)
第一步. 首先栏目和文章最好设置成动态浏览. 这样才不会生成静态html文件.
第二步. 设置重写规则. 在系统目录下加一个 .htaccess文件. 内容为:
复制代码代码如下:
RewriteEngine On
RewriteRule ^plus/list-(<0-9>+).html$ /plus/list.php?tid=$1
RewriteRule ^plus/list-(<0-9>+)-(<0-9>+)-(<0-9>+).html$ /plus/list.php?tid=$1&totalresult=$2&PageNo=$3
RewriteRule ^plus/view-(<0-9>+)-1.html$ /plus/view.php?arcID=$1
RewriteRule ^plus/view-(<0-9>+)-(<0-9>+).html$ /plus/view.php?aid=$1&pageno=$2
iis文件写法
复制代码代码如下:
#首页伪静态规则,如果不使用动态首页,请勿必删除这一行,否则打开首页会出现死循环
RewriteRule ^(.*)/index.html $1/index.php
#列表页伪静态规则
RewriteRule ^(.*)/category/list-(<0-9>+).html $1/plus/list.php?tid=$2
RewriteRule ^(.*)/category/list-(<0-9>+)-(<0-9>+)-(<0-9>+).html $1/plus/list.php?tid=$2&TotalResult=$3&PageNo=$4
#文章页伪静态规则
RewriteRule ^(.*)/archives/view-(<0-9>+)-(<0-9>+).html $1/plus/view.php?arcID=$2&pageno=$3
#搜索伪静态规则
RewriteRule ^(.*)/search.html(?:(?.*))* $1/search.php?$2
#TAG标签伪静态规则
RewriteRule ^(.*)/tags.html $1/tags.php
RewriteRule ^(.*)/tags/(.*)(?:(?.*))* $1/tags.php?/$2
RewriteRule ^(.*)/tags/(.*)/(?:(?.*))* $1/tags.php?/$2/
RewriteRule ^(.*)/tags/(.*)/(<0-9>)(?:(?.*))* $1/tags.php?/$2/$3
RewriteRule ^(.*)/tags/(.*)/(<0-9>)/(?:(?.*))* $1/tags.php?/$2/$3/
如果你的系统支持url重写,到这里就可以用伪静态访问了.
第三步.更改重写的URL.
如果用默认的设置, 访问的URL是:
复制代码代码如下:
http://www.XXXX.com/plus/view-131-1.html
这样的形色, 我们是可以更改这种样式的.
找到文件/include/helpers/channelunit.helper.php打开.
可以看到有这样的语句
复制代码代码如下:
return $GLOBALS<"cfg_plus_dir">."/view-".$aid.'-1.html';
这就是文章的url形色.
$reurl = $GLOBALS<'cfg_phpurl'>."/list.php?tid=".$typeid;
这是列表的重写url.
可以使url更短一点,完成可以写成:
复制代码代码如下:
return "/view-".$aid.'-1.html';
和
$reurl = "/list-".$typeid.".html";
这时重写规则也要更新.
复制代码代码如下:
RewriteEngine On
RewriteRule ^list-(<0-9>+).html$ /plus/list.php?tid=$1
RewriteRule ^list-(<0-9>+)-(<0-9>+)-(<0-9>+).html$ /plus/list.php?tid=$1&totalresult=$2&PageNo=$3
RewriteRule ^view-(<0-9>+)-1.html$ /plus/view.php?arcID=$1
RewriteRule ^view-(<0-9>+)-(<0-9>+).html$ /plus/view.php?aid=$1&pageno=$2
更进一步,还可以把view换成自己的任何词语,这也要把include/arc.archives.class.php文件中的view也一样替换。
发布选项: 生成HTML 仅动态浏览 发文章的时候选一下也不多事。为了以后升级 尽量减少修改文件。
以下这没有试,大家按需要测试吧~~
修改数据库
将所有文档设置为“仅动态”,可以进入数据库管理中,执行下面命令:
复制代码代码如下:
update dede_archives set ismake=-1
并将ismake的默认值设置为 -1即动态。
将所有栏目设置为“使用动态页”,可以进入数据库管理中,执行下面命令:
复制代码代码如下:
update dede_arctype set isdefault=-1
DedeCmsTAG标签伪静态
DedeCms默认的TAG标签URL,形如/tags.php?/dedecms5.7/,非常之难看。打开/include/taglib/tag.lib.php,找到lib_tag()函数下的:
复制代码代码如下:
$row<'link'> = $cfg_cmsurl."/tags.php?/".urlencode($row<'keyword'>)."/";
替换为
$row<'link'> = $cfg_cmsurl."/tags/".urlencode($row<'keyword'>)."/";
修改分页代码
我们需要修改include/arc.taglist.class.php,将分页函数替换为:
复制代码代码如下:
/** * 获取动态的分页列表
*
* @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 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.="<*>上一页rn";
$indexpage="<*>首页rn";
}
else
{
$indexpage="<*>首页rn";
}
if($this->PageNo!=$totalpage && $totalpage>1)
{
$nextpage.="<*>下一页rn";
$endpage="<*>末页rn";
}
else
{
$endpage="<*>末页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; $jPageNo)
{
$listdd.= "$jrn";
}
else
{
$listdd.="<*>".$j."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;
}
文章来源