织梦Dedecms设置伪静态详细方法

所属分类: CMS教程 / dedecms 阅读数: 575
收藏 0 赞 0 分享

首先在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 [I]
#列表页伪静态规则
RewriteRule ^(.*)/category/list-([0-9]+).html $1/plus/list.php?tid=$2 [I]
RewriteRule ^(.*)/category/list-([0-9]+)-([0-9]+)-([0-9]+).html $1/plus/list.php?tid=$2&TotalResult=$3&PageNo=$4 [I]
#文章页伪静态规则
RewriteRule ^(.*)/archives/view-([0-9]+)-([0-9]+).html $1/plus/view.php?arcID=$2&pageno=$3 [I]
#搜索伪静态规则
RewriteRule ^(.*)/search.html(?:(?.*))* $1/search.php?$2 [I]
#TAG标签伪静态规则
RewriteRule ^(.*)/tags.html $1/tags.php [I]
RewriteRule ^(.*)/tags/(.*)(?:(?.*))* $1/tags.php?/$2 [I]
RewriteRule ^(.*)/tags/(.*)/(?:(?.*))* $1/tags.php?/$2/ [I]
RewriteRule ^(.*)/tags/(.*)/([0-9])(?:(?.*))* $1/tags.php?/$2/$3 [I]
RewriteRule ^(.*)/tags/(.*)/([0-9])/(?:(?.*))* $1/tags.php?/$2/$3/ [I]

如果你的系统支持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 <= 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;
}

更多精彩内容其他人还在看

DedeCMS 5 .7 自定义表单制作和调用办法[图文]

在很多建站需求中,需要一些额外的表单供前台用户提交,以便于收集、统计、分析及处理更多的数据,比如:在线订单、在线报名等一些常见的互动应用
收藏 0 赞 0 分享

dedecms 添加字段后软件列表页无法调用软件大小问题的解决方法

最近做模版想在软件列表页(list_soft.htm)利用[field:softsize/]调用软件大小,才发现原来需要如果解决方法
收藏 0 赞 0 分享

织梦DedeCMS模板防盗的四种方法分享

织梦(DedeCMS)模板也是一种财富,不想自己辛辛苦苦做的模板被盗用,在互联网上出现一些和自己一模一样的网站,就需要做好模板防盗
收藏 0 赞 0 分享

dedecms TAG标签按栏目显示的方法

想让dedecms 的TAG标签按栏目显示
收藏 0 赞 0 分享

dedecms修改按tag标签显示全站相关内容的方法

本文简单的设置就可以把dedecms按tag标签显示全站相关内容
收藏 0 赞 0 分享

dedecms正文自动排版插件 伪原创站必备

为了节约时间,站长可以安装dedecms正文自动排版插件,通过该插件,所有的隐藏代码、链接代码、垃圾代码可以一并删除,统一文章格式,方便简单
收藏 0 赞 0 分享

织梦dedecms 提示 body has not allow words 问题解决

body has not allow words DEDE提示这个是什么意思呢
收藏 0 赞 0 分享

dedecms修改文章自动增加的起始ID从指定数字增加文章ID的方法

dedecms织梦文章系统修改文章自动增加的起始ID从指定数字增加文章ID的方法教给大家
收藏 0 赞 0 分享

dedecms V5.7修改表前缀的方法及出现不显示文章内容的解决方法

将下面的内容保存为 pre.bat 内容可以使用记事本批量替换成你的表前缀和想要改成的前缀. window下的ren命令是重命名的
收藏 0 赞 0 分享

织梦 DeDeCMS 添加自定义属性的方法(图文教程)

由于想在网站首页添加一个本站原创内容的版块.又没办法通过版块id来调用,把每篇原创文章添加副栏目又非常麻烦
收藏 0 赞 0 分享
查看更多