织梦dedecms全站伪静态实现方法

2159人参与 |分类: 技术文章|时间: 2019年08月11日
当前位置:网站首页 > 技术文章 > 织梦dedecms全站伪静态实现方法

一 后台-系统参数-核心设置-是否使用伪静态:选择是; 你的网站空间是否支持伪静态,你可以与空间的IDC商联系一下,如果是自己的服务器,那就更好办了,自己动手,丰衣足食。一般来说,空间都是支持伪静态的。Apache服务器伪静态相对简单,直接在.htaccess文...

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

       你的网站空间是否支持伪静态,你可以与空间的IDC商联系一下,如果是自己的服务器,那就更好办了,自己动手,丰衣足食。一般来说,空间都是支持伪静态的。Apache服务器伪静态相对简单,直接在.htaccess文件中加入相应伪静态规则即可;而IIS服务器伪静态的实现,则需要加载Rewrite组件,然后配置httpd.ini文件。 

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

        将所有文档设置为“仅动态浏览”:

update dede_archives set ismake=-1

        将所有栏目设置为“使用动态页”:

update dede_arctype set isdefault=-1

       两个语句必须单独执行,不能同时执行。

三 首页伪静态

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

四 频道、列表页、文章页伪静态修改

       主要通过修改GetFileName()、GetTypeUrl()这两个函数实现。打开/include/helpers/channelunit.helper.php。其他版本如DedeCms V5.3、DedeCms V5.5和DedeCms V5.6版本,打开/include/channelunit.func.php进行修改。

(1)查找:

//动态文章

if($cfg_rewrite == 'Y')

{

return $GLOBALS["cfg_plus_dir"]."/view-".$aid.'-1.html';

}

替换为

//动态文章

if($cfg_rewrite == 'Y')

{

return "/view-".$aid.'-1.html';

}

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

(2) 查找:

//动态

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

替换为

//动态

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

       意思是:将默认的频道或是列表页URL,/plus/list.php?tid=1 变更为/list-1.html形式,减少了一层目录。

五 列表分页伪静态修改

       打开/include/arc.listview.class.php

查找:

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

替换为

$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。这一步也可以不做更改。

六 文章分页伪静态

       打开/include/arc.archives.class.php,找到获取动态的分页列表GetPagebreakDM()函数末尾处:

查找两处的:

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

替换为

$PageList = str_replace('plus', 'archives', $PageList);//将默认的plus替换成archives

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

       意思是:将默认的文章分页链接格式 plus/list-x-x-x.html 修改为 archives/list-x-x-x.html。这一步也可以不做更改。

七 TAG标签伪静态

       DedeCms默认的TAG标签URL,形如/tags.php?/dedecms模板 /,是不是觉得有个问号不怎么爽,我们改成/tags/dedecms模板 /,是不是好看多了。

       下面我们来改一下,打开/include/taglib/tag.lib.php

查找:

$row['link'] = $cfg_cmsurl."/tags.php?/".urlencode($row['keyword'])."/";

替换为

$row['link'] = $cfg_cmsurl."/tags/".urlencode($row['keyword'])."/";

       这样就修改好了,上传到你的网站,切记:要记得将原网站备份哦!

八 搜索伪静态

       dedecms搜索的url伪静态比较麻烦,附带参数多不说,参数也可能变化,搜索结果分页的url特别麻烦,只能偷下懒,将搜索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?”即可。

九 伪静态规则:

       依照上面的步骤修改完毕,接下来配置好httpd.ini文件和.htaccess文件伪静态规则,则DedeCms全站伪静态就完美实现。

1.iis伪静态

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

#首页伪静态规则,如果不使用动态首页,请勿必删除这一行,否则打开首页会出现死循环

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]

#问答伪静态规则,适用于DedeCmsV5.3-5.6版本,需要修改几处程序

RewriteRule ^(.*)/post\.html $1/post\.php [I]

RewriteRule ^(.*)/type\.html $1/type\.php [I]

RewriteRule ^(.*)/question-([0-9]+)\.html $1/question\.php\?id=$2 [I]

RewriteRule ^(.*)/browser-1-([0-9]+)\.html $1/browser\.php\?tid=$2 [I]

RewriteRule ^(.*)/browser-2-([0-9]+)\.html $1/browser\.php\?tid2=$2 [I]

RewriteRule ^(.*)/browser-1-([0-9]+)-([0-9]+)\.html $1/browser\.php\?tid=$2&page=$3 [I]

RewriteRule ^(.*)/browser-2-([0-9]+)-([0-9]+)\.html $1/browser\.php\?tid2=$2&page=$3 [I]

RewriteRule ^(.*)/browser-([0-9]+)\.html $1/browser\.php\?lm=$2 [I]

RewriteRule ^(.*)/browser-1-([0-9]+)-([0-9]+)\.html $1/browser\.php\?tid=$2&lm=$3 [I]

RewriteRule ^(.*)/browser-2-([0-9]+)-([0-9]+)\.html $1/browser\.php\?tid2=$2&lm=$3 [I]

2.Apache伪静态 打开.htaccess文件,加入如下规则:

#提供部分规则作参考

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

RewriteRule ^index.html$ index.php

3、nginx伪静态

location / {

rewrite "^/index.html$" /index.php last;

rewrite "^/list-([0-9]+)\.html$" /plus/list.php?tid=$1 last;

rewrite "^/list-([0-9]+)-([0-9]+)-([0-9]+)\.html$" /plus/list.php?tid=$1&totalresult=$2&PageNo=$3 last;

rewrite "^/view-([0-9]+)-1\.html$" /plus/view.php?arcID=$1 last;

rewrite "^/view-([0-9]+)-([0-9]+)\.html$" /plus/view.php?aid=$1&pageno=$2 last;

rewrite "^/tags/$" /tags.php last;

rewrite "^/tags/(.*)/$" /tags.php?/$1/ last;

break;

}

本文来源:廖维林博客,转载请保留出处和链接!

本文地址: