小言_互联网的博客

织梦DedeCMS5.7设置全站伪静态的方法

257人阅读  评论(0)

织梦是可以生成静态文件的,不过生成静态文件如果有改动的话,需要重新生成,比较麻烦。直接动态的话,对网站的Seo有一点影响,使用伪静态是一个比较好的解决方法,虽然会增加服务器的负载。

首先,网站空间或者服务器需要支持伪静态。这点很重要,不然一切都是白搭。

你可以与空间的IDC商联系一下,如果是自己的服务器,那就更好办了,一般来说,空间都是支持伪静态的。

Apache服务器伪静态相对简单,直接在.htaccess文件中加入相应伪静态规则即可;

而IIS服务器伪静态的实现,则需要加载Rewrite组件,然后配置 httpd.ini文件。

然后,需要在织梦后台开启DedeCms伪静态。

a.后台-系统参数-核心设置-是否使用伪静态:选择“是”;

b.如果你启用了问答模块,则后台-系统参数-模块设置-是否使用伪静态:选择“是”;

c.创建栏目或批量增加栏目时,栏目列表选项:选择“使用动态页”;添加新文章时,发布选项:选择“仅动态浏览 ”。当然,你也可以更改他们的模板,让他们默认就是这两个值,一劳永逸。修改方法很简单,稍懂些HTML基础就行了,这里就不再累述了。

d.如果你的网站已经存在生成的静态栏目或文章HTML,那么只需在后台-系统-SQL命令行工具中执行如下语句:

update dede_arctype se t isdefault=-1;update dede_archives se t ismake=-1;

其中,dede是你安装时的数据表前缀,根据实际情况替换。

事实上,开启DedeCms伪静态支持并不能完全在后台配置,有很多地方还是需要手动修改的,期望官方完善。

织梦DedeCms伪静态,涉及到PHP源码的修改,你可以借助Dreamweaver或是EditPlus一类编辑软件来操作。

下面说下织梦DedeCms5.7全站伪静态的实现方法,适用于V5.3以上版本。

这篇文章说的DedeCms伪静态测试环境是Windows IIS6,举一反三,Linux或其它服务器的伪静态实现原理都是一样的,只要搞清楚思路就行了。

1.DedeCms首页伪静态 把站点根目录下index.html删除,以后不更新主页HTML即可,当然你也可以选择不使用动态首页。

2.DedeCms频道、列表页、文章页伪静态 主要通过修改GetFileName()、GetTypeUrl()这两个函数实现。DedeCms V5.3、DedeCms V5.5和DedeCms V5.6版本,打开/include/channelunit.func.php进行修改。注意:DedeCms V5.7,此文件路径更改了,你打开/include/helpers/channelunit.helper.php即可。

a.将GetFileName()中的如下代码:


  
  1. //动态文章
  2.  if($cfg_rewrite == 'Y') {
  3.  return $GLOBALS["cfg_plus_dir"]."/view-".$aid.'-1.html'; }

替换为


  
  1. //动态文章
  2.  if($cfg_rewrite == 'Y')
  3.  {
  4.  return "/view-".$aid.'-1.html';
  5.  }

将文章页默认的/plus/view-1-1.html链接格式改为/view-1-1.html,这个随个人喜欢,不作更改也行。

b.将GetTypeUrl()中的如下代码:

 //动态 $reurl = $GLOBALS['cfg_phpurl']."/list.php?tid=".$typeid;

替换为

 //动态 $reurl = "/list-".$typeid.".html";

这步必须修改,即让你的频道或是列表页URL变更为/list-1.html形式。

3.DedeCms列表分页伪静态 打开/include/arc.listview.class.php,找到获取动态的分页列表GetPageListDM()函数末尾处:

 $plist = str_replace('.php?tid=', '-', $plist);

替换为


  
  1. $plist = str_replace('plus', 'category', $plist); //将默认的plus替换成category 
  2. $plist = str_replace('.php?tid=', '-', $plist);

将列表分页默认链接格式/plus/list-1-2-1.html修改为/list-1-2-1.html,这步也可以不作更改。

4.DedeCms文章分页伪静态 打开/include/arc.archives.class.php,找到获取动态的分页列表GetPagebreakDM()函数末尾片:

 $PageList = str_replace(".php?aid=","-",$PageList);

替换为


  
  1. $plist = str_replace('plus', 'archives', $plist); //将默认的plus替换成archives 
  2. $PageList = str_replace(".php?aid=","-",$PageList);

这步不作修改也可以,只是个人喜好问题。

5.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'])."/";

到这里,TAG标签URL中的“.php?”号就去掉了。

6.DedeCms搜索伪静态 DedeCms搜索URL静态化比较麻烦,附带参数多不说,参数也可能变化,像搜索结果分页的URL就特麻烦,伪静态规则匹配复杂。随州SEO就偷下懒,将搜索URL中“search.php?…”直接替换为“search.html?…”,至于“?”号之后的参数以任意字符进行匹配。 依次打开include文件夹下的channelunit.func.php、arc.searchview.class.php、 arc.taglist.class.php以及/include/taglib/hotwords.lib.php,查找“search.php?”替换为“search.html?”即可。

7.DedeCms问答伪静态 问答模块的伪静态实现比较简单,只要后台开启伪静态支持即可,至于个别页面,如ask目录下的browser.php、question.php以及 include目录下的common.inc.php、functions.inc.php都需要简单修改才可以匹配伪静态规则。 注意一点,DedeCmsV5.7问答模块整体升级了,之前的规则已经不适用了,以后会专门写个教程供大家参考的。

8.DedeCms伪静态规则 依照上面的步骤修改完毕,接下来配置好你的伪静态规则,DedeCms全站伪静态就完美实现了。

1)IIS伪静态 打开httpd.ini文件,加入如下规则:


  
  1. #首页伪静态规则,如果不使用动态首页,请勿必删除这一行,否则打开首页会出现死循环 
  2. RewriteRule ^(.*)/index\.html $1/index\.php [I] 
  3. #列表页伪静态规则 
  4. RewriteRule ^(.*)/list-([0-9]+)\.html $1/plus/list\.php\?tid=$2 [I] 
  5. RewriteRule ^(.*)/list-([0-9]+)-([0-9]+)-([0-9]+)\.html $1/plus/list\.php\?tid=$2&TotalResult=$3&PageNo=$4 [I] 
  6. #文章页伪静态规则 
  7. RewriteRule ^(.*)/view-([0-9]+)-([0-9]+)\.html $1/plus/view\.php\?arcID=$2&pageno=$3 [I] 
  8. #搜索伪静态规则 
  9. RewriteRule ^(.*)/search\.html(?:(\?.*))* $1/search\.php?$2 [I] 
  10. #TAG标签伪静态规则 
  11. RewriteRule ^(.*)/tags\.html $1/tags\.php [I] RewriteRule ^(.*)/tags/(.*)(?:(\?.*))* $1/tags\.php\?\/$2 [I] 
  12. RewriteRule ^(.*)/tags/(.*)\/(?:(\?.*))* $1/tags\.php\?\/$2\/ [I] 
  13. RewriteRule ^(.*)/tags/(.*)\/([0-9])(?:(\?.*))* $1/tags\.php\?\/$2\/$3 [I] 
  14. RewriteRule ^(.*)/tags/(.*)\/([0-9])\/(?:(\?.*))* $1/tags\.php\?\/$2\/$3\/ [I] 
  15. #问答伪静态规则,适用于DedeCmsV5.3-5.6版本,需要修改几处程序 
  16. RewriteRule ^(.*)/post\.html $1/post\.php [I] 
  17. RewriteRule ^(.*)/type\.html $1/type\.php [I] 
  18. RewriteRule ^(.*)/question-([0-9]+)\.html $1/question\.php\?id=$2 [I] 
  19. RewriteRule ^(.*)/browser-1-([0-9]+)\.html $1/browser\.php\?tid=$2 [I] 
  20. RewriteRule ^(.*)/browser-2-([0-9]+)\.html $1/browser\.php\?tid2=$2 [I] 
  21. RewriteRule ^(.*)/browser-1-([0-9]+)-([0-9]+)\.html $1/browser\.php\?tid=$2&page=$3 [I] 
  22. RewriteRule ^(.*)/browser-2-([0-9]+)-([0-9]+)\.html $1/browser\.php\?tid2=$2&page=$3 [I] 
  23. RewriteRule ^(.*)/browser-([0-9]+)\.html $1/browser\.php\?lm=$2 [I] 
  24. RewriteRule ^(.*)/browser-1-([0-9]+)-([0-9]+)\.html $1/browser\.php\?tid=$2&lm=$3 [I] 
  25. RewriteRule ^(.*)/browser-2-([0-9]+)-([0-9]+)\.html $1/browser\.php\?tid2=$2&lm=$3 [I]

2)Apache伪静态

打开.htaccess文件,加入如下规则:


  
  1. RewriteRule ^"^/list-([0-9]+)\.html$" plus/list.php?tid=$1
  2. RewriteRule ^"^/list-([0-9]+)-([0-9]+)-([0-9]+)\.html$" plus/list.php?tid=$1&totalresult=$2&PageNo=$3
  3. RewriteRule ^"^/view-([0-9]+)-1\.html$" plus/view.php?arcID=$1
  4. RewriteRule ^"^/view-([0-9]+)-([0-9]+)\.html$" plus/view.php?aid=$1&pageno=$2
  5. RewriteRule ^"^/tags.html$" tags.php
  6. RewriteRule ^"^/tag-([0-9]+)-([0-9]+)\.html$" tags.php?/$1/$2

3)Nginx伪静态


  
  1. location / {
  2. rewrite "^/list-([0-9]+)\.html$" /plus/list.php?tid=$1 last;
  3. rewrite "^/list-([0-9]+)-([0-9]+)-([0-9]+)\.html$" /plus/list.php?tid=$1&totalresult=$2&PageNo=$3 last;
  4. rewrite "^/view-([0-9]+)-1\.html$" /plus/view.php?arcID=$1 last;
  5. rewrite "^/view-([0-9]+)-([0-9]+)\.html$" /plus/view.php?aid=$1&pageno=$2 last;
  6. rewrite "^/tags.html$" /tags.php last;
  7. rewrite "^/tag-([0-9]+)-([0-9]+)\.html$" /tags.php?/$1/$2/ last;
  8. break;
  9. }

至此,织梦DedeCMS5.7的全站伪静态就完成了。


转载:https://blog.csdn.net/qq_39339179/article/details/116840475
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场