此篇为系列教程,为还在为dz伪静态烦恼的站长们助力(译版:为了申请版主而做准备)!
以discuz!3.2 + nginx为例!Apache,iis请自行转换!
【重要提醒:修改前请备份源文件,如果发现修改后进入页面空白,请检查代码是否修改正确!】
由于这个是把重要的代码全部【code】化,所以看起来会比较累!
所以提供百度文库及其豆丁版(都是本人上传,版主如果觉得有广告嫌疑请删除此段)
百度文库:
http://wenku.baidu.com/view/dbd9758e76c66137ee0619ae
豆丁:http://www.docin.com/p-1150291362.html
注意:此方案将使“主题分类”链接伪静态化,但将去掉“分类信息”在版块中的显示链接(不影响实际帖子中显示分类信息),同时将去掉原有的部分排序功能:热帖(多数版块内容不多,保留按热度值排序的“热门”功能即可),时间排序(不完善,无意义)。
1、首先添加伪静态规则(以Nginx为例):
rewrite ^([^\.]*)/forum-([0-9]+)-h([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&filter=heat&orderby=heats&page=$3 last;
rewrite ^([^\.]*)/forum-([0-9]+)-d([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&filter=digest&digest=1&page=$3 last;
rewrite ^([^\.]*)/forum-([0-9]+)-l([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&filter=lastpost&orderby=lastpost&page=$3 last;
rewrite ^([^\.]*)/forum-([0-9]+)-n([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&filter=author&orderby=dateline&page=$3 last;
rewrite ^([^\.]*)/forum-([0-9]+)-r([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&filter=reply&orderby=replies&page=$3 last;
rewrite ^([^\.]*)/forum-([0-9]+)-v([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&filter=reply&orderby=views&page=$3 last;
rewrite ^([^\.]*)/forum-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&filter=typeid&typeid=$3&page=$4 last;
rewrite ^([^\.]*)/forum-([0-9]+)-([0-9]+)-d([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&filter=digest&digest=1&typeid=$3&page=$4 last;
rewrite ^([^\.]*)/forum-([0-9]+)-([0-9]+)-l([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&filter=lastpost&orderby=lastpost&typeid=$3&page=$4 last;
rewrite ^([^\.]*)/forum-([0-9]+)-([0-9]+)-n([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&filter=author&orderby=dateline&typeid=$3&page=$4 last;
rewrite ^([^\.]*)/forum-([0-9]+)-([0-9]+)-r([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&filter=reply&orderby=replies&typeid=$3&page=$4 last;
rewrite ^([^\.]*)/forum-([0-9]+)-([0-9]+)-v([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&filter=reply&orderby=views&typeid=$3&page=$4 last;
rewrite ^([^\.]*)/forum-([0-9]+)-dl([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&filter=digest&digest=1&orderby=lastpost&page=$3 last;
rewrite ^([^\.]*)/forum-([0-9]+)-dn([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&filter=digest&digest=1&orderby=dateline&page=$3 last;
rewrite ^([^\.]*)/forum-([0-9]+)-dr([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&filter=digest&digest=1&orderby=replies&page=$3 last;
rewrite ^([^\.]*)/forum-([0-9]+)-dv([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&filter=digest&digest=1&orderby=views&page=$3 last;
rewrite ^([^\.]*)/forum-([0-9]+)-([0-9]+)-dl([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&filter=digest&digest=1&orderby=lastpost&typeid=$3&page=$4 last;
rewrite ^([^\.]*)/forum-([0-9]+)-([0-9]+)-dn([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&filter=digest&digest=1&orderby=dateline&typeid=$3&page=$4 last;
rewrite ^([^\.]*)/forum-([0-9]+)-([0-9]+)-dr([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&filter=digest&digest=1&orderby=replies&typeid=$3&page=$4 last;
rewrite ^([^\.]*)/forum-([0-9]+)-([0-9]+)-dv([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&filter=digest&digest=1&orderby=views&typeid=$3&page=$4 last;
以上规则依次为 热度(评价)排序、精华帖、最后回复时间排序、按发帖时间排序、最多回复排序、最多浏览排序、主题分类、分类下精华帖、分类按最后回复排序、分类按发帖时间排序、分类按最多回复排序、分类按浏览次数排序、精华按最后回复时间排序、精华按发帖时间排序、精华按最多回复排序、精华按最多浏览排序、分类下精华按最后回复时间排序、分类下精华按发帖时间排序、分类下精华按最多回复排序、分类下精华按最多浏览排序。
注意:必须添加在“插件”页面的伪静态规则(即 rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3 last; 行)之前的任意位置。添加后需要 重载 或 关闭后再启动 Nginx后生效(仅直接重启无效)。
2、版块页帖子列表上方主题分类链接伪静态。打开 forum/forumdisplay.htm 模板,将
forum.php?mod=forumdisplay&fid=$_G[fid]&filter=typeid&typeid=$id$forumdisplayadd[typeid]{if $_GET['archiveid']}&archiveid={$_GET['archiveid']}{/if}[ /code]替换为 [code]forum-$_G[fid]-$id-1.html
3、取消已选中分类上的链接(SEO)(否则同一个关键词上会根据选中与未选中有两个不同链接)。同样打开 forum/forumdisplay.htm 模板,将以下整段代码:
<li class="xw1 a"><a href="forum.php?mod=forumdisplay&fid=$_G[fid]{if $_GET['sortid']}&filter=sortid&sortid=$_GET['sortid']{/if}{if $_GET['archiveid']}&archiveid={$_GET['archiveid']}{/if}"><!--{if $_G[forum][threadtypes][icons][$id] && $_G['forum']['threadtypes']['prefix'] == 2}--><img class="vm" src="$_G[forum][threadtypes][icons][$id]" alt="" /> <!--{/if}-->$name<!--{if $showthreadclasscount[typeid][$id]}--><span class="xg1 num">$showthreadclasscount[typeid][$id]</span><!--{/if}--></a></li>
替换为:
<li style="margin-right:5px; padding:4px 8px 3px; height:18px; font-weight:700; color:#369; float:left; border:1px solid #369; background:#eef5fa; white-space:nowrap;"><!--{if $_G[forum][threadtypes][icons][$id] && $_G['forum']['threadtypes']['prefix'] == 2}--><img class="vm" src="$_G[forum][threadtypes][icons][$id]" alt="" /> <!--{/if}-->$name<!--{if $showthreadclasscount[typeid][$id]}--><span class="xg1 num">$showthreadclasscount[typeid][$id]</span><!--{/if}--></li>
4、将选中分类时列表中的帖子链接伪静态化。打开 forum/forumdisplay_list.htm 模板,将:
<a href="forum.php?mod=viewthread&tid=$thread[tid]&{if $_GET['archiveid']}archiveid={$_GET['archiveid']}&{/if}extra=$extra"$thread[highlight]{if $thread['isgroup'] == 1 || $thread['forumstick']} target="_blank"{else}{/if} class="s xst">$thread[subject]</a>
替换为:
<a href="forum.php?mod=viewthread&tid=$thread[tid]"{$thread[highlight]} {if $thread['isgroup'] == 1 || $thread['forumstick']}target="_blank"{else}onclick="atarget(this)"{/if} class="s xst">$thread[subject]</a>
修改后,当选中分类时,列表中的帖子链接将伪静态化,但帖子的分页链接仍未动态,还需进行以下修改。
打开 source/module/forum/forum_forumdisplay.php 文件,将:
<a href=\"forum.php?mod=viewthread&tid=$realtid&".(!empty($multipate_archive) ? "$multipate_archive&" : '')."extra=$extra&page=$i\">
替换为:
<a href=\"thread-$realtid-$i-1.html\" onclick=\"atarget(this)\">
将:
<a href=\"forum.php?mod=viewthread&tid=$realtid&".(!empty($multipate_archive) ? "$multipate_archive&" : '')."extra=$extra&page=$thread[pages]\">
替换为:
<a href=\"thread-$realtid-$thread[pages]-1.html\" onclick=\"atarget(this)\">
5、将版块页帖子标题前方的 主题分类 链接伪静态化。打开 source/module/forum/forum_forumdisplay.php 文件,将:
forum.php?mod=forumdisplay&fid='.$_G['fid'].'&filter=typeid&typeid='.$thread['typeid'].'
共两处,替换为:
forum-'.$_G['fid'].'-'.$thread['typeid'].'-1.html
6、当处于某分类时,针对搜索引擎隐藏帖子列表中大量重复的主题分类名称及其链接(SEO)。打开 forum/forumdisplay_list.htm 模板
将
$thread[typehtml]
替换为:
<!--{if !(IS_ROBOT && $_GET['typeid'])}-->$thread[typehtml]<!--{/if}-->
7、当处于主题分类时,主题列表翻页链接伪静态化。
打开 source/module/forum/forum_forumdisplay.php 文件,查找:
$multipage = multi($_G['forum_threadcount'], $_G['tpp'], $page, "forum.php?mod=forumdisplay&fid=$_G[fid]".$forumdisplayadd['page'].($multiadd ? '&'.implode('&', $multiadd) : '')."$multipage_archive", $_G['setting']['threadmaxpages']);
将其替换为:
if($_GET['typeid']) {
$url_typeid = $_GET['typeid'].'-';
}
if($_GET['filter'] == 'digest') {
$url_filter = 'd';
} elseif($_GET['filter'] == 'heat') {
$url_filter = 'h';
}
if($_GET['filter'] && $_GET['filter'] != 'typeid') {
if($_GET['orderby'] == 'dateline') {
$url_orderby = 'n';
} elseif($_GET['orderby'] == 'lastpost') {
$url_orderby = 'l';
} elseif($_GET['orderby'] == 'replies') {
$url_orderby = 'r';
} elseif($_GET['orderby'] == 'views') {
$url_orderby = 'v';
}
}
$multipage = multi_forum($_G['forum_threadcount'], $_G['tpp'], $page, "forum-$_G[fid]-".$url_typeid.$url_filter.$url_orderby, $_G['setting']['threadmaxpages']);
打开 source/function/function_core 文件,
在
function simplepage($num, $perpage, $curpage, $mpurl) {
前面增加一段(定义multi_forum):
function multi_forum($num, $perpage, $curpage, $mpurl, $maxpages = 0, $page = 10, $autogoto = FALSE, $simple = FALSE, $jsfunc = FALSE) {
return $num > $perpage ? helper_page_forum::multi($num, $perpage, $curpage, $mpurl, $maxpages, $page, $autogoto, $simple, $jsfunc) : '';
}
进入 source/class/helper/ 目录,将 helper_page.php 复制一份命名为 helper_page_forum.php 。并依次修改 helper_page_forum.php 文件中的以下部分:
将 helper_page 修改为 helper_page_forum (共两处,其中文件头注释中的那处无关紧要);
将
$pagevar = 'page=';
修改为
$pagevar = '';
将
$jsurl = $mpurl.(strpos($mpurl, '{page}') !== false ? '\'.replace(\'{page}\', this.value == 1 ? \'\' : this.value)': $pagevar.'\'+this.value;').'; doane(event);';
修改为
$jsurl = substr($mpurl, 0, -1).(strpos($mpurl, '{page}') !== false ? '\'.replace(\'{page}\', this.value == 1 ? \'\' : this.value)': $pagevar.'\'+this.value').'+\'.html\'; doane(event);';
(此项操作使手动输入页码翻页时链接静态化);
将
return $mpurl.$separator.$pagevar.$page;
修改为
return substr($mpurl, 0, -1).$separator.$pagevar.$page.'.html';
(翻页页码链接静态化)。
8、帖子内容页标题前方主题分类链接伪静态化。打开 forum/viewthread.htm 文件,查找:
<a href="forum.php?mod=forumdisplay&fid=$_G[fid]&filter=typeid&typeid=$_G[forum_thread][typeid]">[{$_G['forum']['threadtypes']['types'][$_G['forum_thread']['typeid']]}]</a>
替换为:
[<a href="forum-{$_G[fid]}-{$_G[forum_thread][typeid]}-1.html">{$_G['forum']['threadtypes']['types'][$_G['forum_thread']['typeid']]}</a>]
为使搜索引擎可以收录主题分类链接,可将上方的
<!--{if !IS_ROBOT && ($_G['forum']['threadtypes']['listable'] || $_G['forum']['status'] == 3)}-->
修改为
<!--{if $_G['forum']['threadtypes']['listable'] || $_G['forum']['status'] == 3}-->
9、版块主题列表页筛选与排序链接伪静态化。打开 forum/forumdisplay_list.htm 模板,搜索:
<!--{if !IS_ROBOT}--> 从它开始(包括它)一直到 <!--{if $multipage && $filter != 'hot'}--> 之前的 <!--{/if}--> 整段删除(这是筛选功能的弹出菜单,不再需要,我们下面直接列出菜单,注意:将不再保留按天数筛选的功能)。
搜索 <div class="tf"> ,此它开始(包括它)一直到 <!--{hook/forumdisplay_filter_extra}--> 下面的 </div>整段替换为:
<div class="tf" style="padding-left:5px;">
<span id="atarget" {if $_G['cookie']['atarget'] > 0}onclick="setatarget(-1)" class="y atarget_1"{else}onclick="setatarget(1)" class="y"{/if} title="{lang new_window_thread}">{lang new_window}</span>
主题筛选:
[code]<a href="forum-$_G[fid]-{if $_GET['orderby'] == 'dateline'}n{elseif $_GET['orderby'] == 'lastpost'}l{elseif $_GET['orderby'] == 'replies'}r{elseif $_GET['orderby'] == 'views'}v{/if}1.html" rel="nofollow" style="color:#369;{if !preg_match("/(heat|digest|specialtype)/i", $_GET['filter'])}font-weight:bold;{/if}">全部</a>
<a href="forum-$_G[fid]-h1.html" rel="nofollow" style="color:#369;{if $_GET['filter'] == 'heat'}font-weight:bold;{/if}">热帖</a>
<a href="forum-$_G[fid]{if $_GET['typeid']}-$_GET['typeid']{/if}-d{if $_GET['orderby'] == 'dateline'}n{elseif $_GET['orderby'] == 'lastpost'}l{elseif $_GET['orderby'] == 'replies'}r{elseif $_GET['orderby'] == 'views'}v{/if}1.html" rel="nofollow" style="color:#369;{if $_GET['filter'] == 'digest'}font-weight:bold;{/if}">精华</a>
排序:
<a href="forum-$_G[fid]{if $_GET['typeid']}-$_GET['typeid']{/if}-{if $_GET['filter'] == 'digest'}d{/if}l1.html" rel="nofollow" style="color:#369;{if $_GET['orderby'] == 'lastpost'}font-weight:bold;{/if}">最近回复</a>
<a href="forum-$_G[fid]{if $_GET['typeid']}-$_GET['typeid']{/if}-{if $_GET['filter'] == 'digest'}d{/if}n1.html" rel="nofollow" style="color:#369;{if $_GET['orderby'] == 'dateline'}font-weight:bold;{/if}">最新帖子</a>
<a href="forum-$_G[fid]{if $_GET['typeid']}-$_GET['typeid']{/if}-{if $_GET['filter'] == 'digest'}d{/if}r1.html" rel="nofollow" style="color:#369;{if $_GET['orderby'] == 'replies'}font-weight:bold;{/if}">最多回帖</a>
<a href="forum-$_G[fid]{if $_GET['typeid']}-$_GET['typeid']{/if}-{if $_GET['filter'] == 'digest'}d{/if}v1.html" rel="nofollow" style="color:#369;{if $_GET['orderby'] == 'views'}font-weight:bold;{/if}">最多查看</a>
<!--{if empty($_G['forum']['picstyle']) && $_GET['orderby'] == 'lastpost' && (!$_G['setting']['forumseparator'] || !$separatepos) && !$_GET['filter']}-->
<a href="javascript:;" title="{lang showupgrade}" class="forumrefresh"></a>
<!--{/if}-->
<span id="clearstickthread" style="display: none;">
<span class="pipe">|</span>
<a href="javascript:;" class="xi2"">恢复隐藏置顶</a>
</span>
<!--{hook/forumdisplay_filter_extra}-->
</div>
将
{lang title}
替换为:
[code]<div class="tf" style="padding-left:5px;">主题列表</div>[/code]
10、最后,在根目录 robots.txt 文件中添加:
[code]Disallow: /forum-*h*.html
Disallow: /forum-*d*.html
Disallow: /forum-*l*.html
Disallow: /forum-*n*.html
Disallow: /forum-*r*.html
Disallow: /forum-*v*.html[/code]
【discuz伪静态】系列之一:http://bbs.aliyun.com/read/244384.html
【discuz伪静态】系列之二:http://bbs.aliyun.com/read/244388.html
【discuz伪静态】系列之三:
http://bbs.aliyun.com/read/244531.html
【discuz伪静态】系列之四:http://bbs.aliyun.com/read/244529.html
【discuz伪静态】系列之五(附件篇):
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。