找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1103|回复: 0
打印 上一主题 下一主题

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

[复制链接]

2500

主题

2513

帖子

7520

积分

论坛元老

Rank: 8Rank: 8

积分
7520
跳转到指定楼层
楼主
发表于 2018-2-13 20:38:17 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

首先在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&ageNo=$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&ampageNo=$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&ageNo=$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->ageNo - 1;
        $nextpagenum = $this->ageNo + 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->ageNo != 1)
        {
            $prepage.="
  • 上一页rn";
                $indexpage="
  • 首页rn";
            }
            else
            {
                $indexpage="
  • 首页rn";
            }
            if($this->ageNo!=$totalpage && $totalpage>1)
            {
                $nextpage.="
  • 下一页rn";
                $endpage="
  • 末页rn";
            }
            else
            {
                $endpage="
  • 末页rn";
            }

            //获得数字链接
            $listdd="";
            $total_list = $list_len * 2 + 1;
            if($this->ageNo >= $total_list)
            {
                $j = $this->ageNo - $list_len;
                $total_list = $this->ageNo + $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;
        }
  • 分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    用户反馈
    客户端