闯天下 發表於 2023-8-6 00:00:00

dedecms全站伪静态的实现方法及注意事项

<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        成都SEO告诉你,用系统自带生成静态的麻烦事情很多,特别是文章多了,更新一点东西之类的就很是麻烦。所以成都SEO建议,大家如果能用伪静态就都用伪静态吧!一劳永逸的事情,以后不用再给大批量的更新而烦恼了。在此分享一下DEDECMS实现频道|列表页|文章页|TAG伪静态的方法,希望朋友们在有需要的时候能用上吧!</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <strong>开启伪静态的前提条件</strong></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        保证你的空间或服务器支持伪静态即URL重写</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <strong>开启DedeCms伪静态</strong></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        开启伪静态的方法:后台--》系统--》核心设置 找到:是否使用伪静态: 选择是 确定保存。<br>
        栏目和文章发布设置<br>
        栏目列表选项: 选择使用动态页 发布选项: 选择仅动态浏览<br>
        DEDECMS全站伪静态方法<br>
        首页伪静态<br>
        把站点根目录下index.html删除,以后不更新主页HTML即可,当然你也可以选择不使用动态首页。<br>
        频道、列表、文章伪静态<br>
        主要通过修改GetFileName()、GetTypeUrl()这两个函数实现。DedeCms V5.3、DedeCms V5.5和DedeCms V5.6版本,打开/include/channelunit.func.php进行修改。注意:DedeCms V5.7,此文件路径更改了,你打开/include/helpers/channelunit.helper.php即可。<br>
        a.将GetFileName()中的如下代码:<br>
        //动态文章<br>
        if($cfg_rewrite == 'Y')<br>
        {<br>
        return $GLOBALS["cfg_plus_dir"]."/view-".$aid.'-1.html';<br>
        }<br>
        替换为<br>
        //动态文章<br>
        if($cfg_rewrite == 'Y')<br>
        {<br>
        return "/archives/view-".$aid.'-1.html';<br>
        }<br>
        将文章页默认的/plus/view-1-1.html链接格式改为/archives/view-1-1.html,这个随个人喜欢,不作更改也行。<br>
        b.将GetTypeUrl()中的如下代码:<br>
        //动态<br>
        $reurl = $GLOBALS['cfg_phpurl']."/list.php?tid=".$typeid;<br>
        替换为<br>
        //动态<br>
        $reurl = "/category/list-".$typeid.".html";<br>
        这步必须修改,即让你的频道或是列表页URL变更为/category/list-1.html形式。<br>
        列表分页伪静态<br>
        打开/include/arc.listview.class.php,找到获取动态的分页列表GetPageListDM()函数末尾处:<br>
        $plist = str_replace('.php?tid=', '-', $plist);<br>
        替换为<br>
        $plist = str_replace('plus', 'category', $plist);//将默认的plus替换成category$plist = str_replace('.php?tid=', '-', $plist);将列表分页默认链接格式/plus/list-1-2-1.html修改为/category/list-1-2-1.html,这步也可以不作更改。<br>
        DEDECMS文章分页伪静态<br>
        打开/include/arc.archives.class.php,找到获取动态的分页列表GetPagebreakDM()函数末尾处:<br>
        $PageList = str_replace(".php?aid=","-",$PageList);<br>
        替换为<br>
        $plist = str_replace('plus', 'archives', $plist);//将默认的plus替换成archives$PageList = str_replace(".php?aid=","-",$PageList);这步不作修改也可以,只是个人喜好问题。<br>
        TAG标签伪静态<br>
        DedeCms默认的TAG标签URL,形如/tags.php?/dedecms5.7/,非常之难看。打开/include/taglib/tag.lib.php,找到lib_tag()函数下的:<br>
        $row['link'] = $cfg_cmsurl."/tags.php?/".urlencode($row['keyword'])."/";<br>
        替换为<br>
        $row['link'] = $cfg_cmsurl."/tags/".urlencode($row['keyword'])."/";到这里,TAG标签URL中的“.php?”号就去掉了。<br>
        搜索伪静态<br>
        DedeCms搜索URL静态化比较麻烦,附带参数多不说,参数也可能变化,像搜索结果分页的URL就特麻烦,伪静态规则匹配复杂。小拼就偷下懒,将搜索URL中“search.php?…”直接替换为“search.html?…”,至于“?”号之后的参数以任意字符进行匹配。<br>
        依次打开include文件夹下的channelunit.func.php、arc.searchview.class.php、arc.taglist.class.php以及/include/taglib/hotwords.lib.php,查找“search.php?”替换为“search.html?”即可。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <strong>下面是规则:</strong></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        本篇文章主要新增了适用于dedecms的个性化伪静态文章链接设置,以及网站的目录链接301跳转和文章链接301跳转规则!各位有不懂的可以留言,我尽最大努力帮助大家!</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <strong>htaccess伪静态的规则</strong></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        通过htaccess使用伪静态,则必须空间商支持Rewrite模块,该模块负责URL的重写。否则即便是设置好了,也无法使用,并且还有可能出现500错误。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        下面是dedecms的伪静态设置文本(部分参考):</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        个性化伪静态还需要配合修改dedecms后台文件才能实现</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        效果为www.***.com/plus/view.php?aid=123转化为www.***.com/html/123/123.html</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        具体规则大家可以根据自己的需要进行修改!</p>
<div class="jb51code" style='margin: 0px; padding: 0px; outline: none; line-height: 25.2px; font-size: 14px; width: 660px; overflow: hidden; clear: both; font-family: tahoma, arial, "Microsoft YaHei";'>
        <pre class="brush:plain;">
RewriteEngine On
RewriteRule ^category/list-(+)\.html$ /plus/list.php?tid=$1
RewriteRule ^category/list-(+)-(+)-(+)\.html$ /plus/list.php?tid=$1&amp;totalresult=$2&amp;PageNo=$3
RewriteRule ^archives/view-(+)-(+)\.html$ /plus/view.php?arcID=$1&amp;pageno=$2
RewriteRule ^plus/list-(+).html$ /plus/list.php?tid=$1   
RewriteRule ^plus/list-(+)-(+)-(+).html$ /plus/list.php?tid=$1&amp;totalresult=$2&amp;PageNo=$3   
RewriteRule ^plus/view-(+)-1.html$ /plus/view.php?arcID=$1   
RewriteRule ^plus/view-(+)-(+).html$ /plus/view.php?aid=$1&amp;pageno=$2//个性化伪静态文章链接
RewriteRule ^list_(+)-(+)-(+).html$ list.php?tid=$1&amp;TotalResult=$2&amp;PageNo=$3
RewriteRule ^html/(+)(+)/(+).html$ /plus/view.php?aid=$3
</pre>
</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        5.目录和文章链接的301跳转</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        该功能可以实现网站目录链接和文章链接的301跳转</p>
<div class="jb51code" style='margin: 0px; padding: 0px; outline: none; line-height: 25.2px; font-size: 14px; width: 660px; overflow: hidden; clear: both; font-family: tahoma, arial, "Microsoft YaHei";'>
        <pre class="brush:xhtml;">
RewriteEngine On
RewriteBase /
RewriteRule ^html/it/(.+)$ https://www.***.com/html/$1 </pre>
</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        效果是:访问www.***.com/html/it/*.html 会跳转到www.***.com/html/.html 这个上面</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <strong>注意事项</strong></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        以上都是需要伪静态的地方。值得注意的一点是:在进行任何一步的操作之前先将文档都进行备份,以防万一。以上方法也不是我原创的,纯属网络上搜集的。实践过,都能用的哈。如果有问题可以给我留言,修正不对的地方,但很有可能是你的操作失误哈,这些伪静态的到5.7版本都可以用。</p>
頁: [1]
查看完整版本: dedecms全站伪静态的实现方法及注意事项