昨天看到有朋友需要,然后今天抽时间整理了一下
要提醒:修改前请备份源文件,如果发现修改后进入页面空白,请检查代码是否修改正确!】
由于这个是把重要的代码全部【code】化,所以看起来会比较累!
所以提供百度文库及其豆丁版(都是本人上传,版主如果觉得有广告嫌疑请删除此段)
以discuz!3.4 + nginx为例!Apache,iis请自行转换!
一.【discuz伪静态】之:主题分类与排序功能伪静态
注意:此方案将使“主题分类”链接伪静态化,但将去掉“分类信息在版块中的显示链接(不影响实际帖子中显示分类信息),同时将去掉原有的部分排序功能:热帖(多数版块内容不多,保留按热度值排序的“热门”功能即可),时间排序(不完善,无意义)。
1、首先添加伪静态规则(以Nginx为例):
本部分内容设定了隐藏,需要回复后才能看到
以上规则依次为 热度(评价)排序、精华帖、最后回复时间排序、按发帖时间排序、最多回复排序、最多浏览排序、主题分类、分类下精华帖、分类按最后回复排序、分类按发帖时间排序、分类按最多回复排序、分类按浏览次数排序、精华按最后回复时间排序、精华按发帖时间排序、精华按最多回复排序、精华按最多浏览排序、分类下精华按最后回复时间排序、分类下精华按发帖时间排序、分类下精华按最多回复排序、分类下精华按最多浏览排序。
注意:必须添加在“插件”页面的伪静态规则
rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2
3 last;之前的任意位置
2、版块页帖子列表上方主题分类链接伪静态。打开 forum/forumdisplay.htm 模板,将
forum.php?mod=forumdisplay&fid=$_G[fid]&filter=typeid&typeid=$id$forumdisplayadd[typeid]{if $_GET['archiveid']}&archiveid={$_GET['archiveid']}{/if}替换为
forum-$_G[fid]-$id-1.html3、取消已选中分类上的链接(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'].'[color=rgb(51, 51, 51)]共两处,替换为:
forum-'.$_G['fid'].'-'.$thread['typeid'].'-1.html[color=rgb(51, 51, 51)]6、当处于某分类时,针对搜索引擎隐藏帖子列表中大量重复的主题分类名称及其链接(SEO)。打开 forum/forumdisplay_list.htm 模板
[color=rgb(51, 51, 51)]将
$thread[typehtml]替换为
<!--{if !(IS_ROBOT && $_GET['typeid'])}-->$thread[typehtml]<!--{/if}-->[color=rgb(51, 51, 51)]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']);[color=rgb(51, 51, 51)]打开 source/function/function_core 文件,
[color=rgb(51, 51, 51)]在
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) : '';
}[color=rgb(51, 51, 51)]进入 source/class/helper/ 目录,将 helper_page.php 复制一份命名为 helper_page_forum.php 。并依次修改 helper_page_forum.php 文件中的以下部分:
[color=rgb(51, 51, 51)]将 helper_page 修改为 helper_page_forum (共两处,其中文件头注释中的那处无关紧要);
[color=rgb(51, 51, 51)]将
$pagevar = 'page=';修改为
$pagevar = '';[color=rgb(51, 51, 51)]将
$jsurl = $mpurl.(strpos($mpurl, '{page}') !== false ? '\'.replace(\'{page}\', this.value == 1 ? \'\' : this.value)': $pagevar.'\'+this.value;').'; doane(event);';[color=rgb(51, 51, 51)]修改为
$jsurl = substr($mpurl, 0, -1).(strpos($mpurl, '{page}') !== false ? '\'.replace(\'{page}\', this.value == 1 ? \'\' : this.value)': $pagevar.'\'+this.value').'+\'.html\'; doane(event);';[color=rgb(51, 51, 51)](此项操作使手动输入页码翻页时链接静态化);
将
return $mpurl.$separator.$pagevar.$page;修改为
return substr($mpurl, 0, -1).$separator.$pagevar.$page.'.html';[color=rgb(51, 51, 51)](翻页页码链接静态化)。
[color=rgb(51, 51, 51)]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>[color=rgb(51, 51, 51)]替换为:
[<a href=\"forum-{$_G[fid]}-{$_G[forum_thread][typeid]}-1.html\">{$_G['forum']['threadtypes']['types'][$_G['forum_thread']['typeid']]}</a>][color=rgb(51, 51, 51)]为使搜索引擎可以收录主题分类链接,可将上方的
<!--{if !IS_ROBOT && ($_G['forum']['threadtypes']['listable'] || $_G['forum']['status'] == 3)}-->[color=rgb(51, 51, 51)]修改为
<!--{if $_G['forum']['threadtypes']['listable'] || $_G['forum']['status'] == 3}-->
[color=rgb(51, 51, 51)]9、版块主题列表页筛选与排序链接伪静态化。打开 forum/forumdisplay_list.htm 模板,搜索:
[color=rgb(51, 51, 51)]<!--{if !IS_ROBOT}--> 从它开始(包括它)一直到 <!--{if $multipage && $filter != 'hot'}--> 之前的 <!--{/if}--> 整段删除(这是筛选功能的弹出菜单,不再需要,我们下面直接列出菜单,注意:将不再保留按天数筛选的功能)。
[color=rgb(51, 51, 51)]搜索 <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}替换为
<span style=\"color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 21.6px; background-color: rgb(255, 255, 255);\"><div class=\"tf\" style=\"padding-left:5px;\">主题列表</div></span>[color=rgb(51, 51, 51)]10、最后,在根目录 robots.txt 文件中添加:
Disallow: /forum-*h*.html
Disallow: /forum-*d*.html
Disallow: /forum-*l*.html
Disallow: /forum-*n*.html
Disallow: /forum-*r*.html
Disallow: /forum-*v*.html二.【discuz伪静态】之:TAG标签伪静态
以discuz!3.4 + nginx为例!Apache,iis请自行转换!
[color=rgb(51, 51, 51)]我记得好像从Discuz X3.2开始默认是禁止搜索引擎访问 misc.php 文件的,因此 tag 不会被收录。
[color=rgb(51, 51, 51)]我们可以将 tag 网址伪静态化,这样不仅使 tag 网址看上去更规范美观,还使 tag 页面可以被百度收录。
1、添加伪静态规则(以Nginx为例):
本部分内容设定了隐藏,需要回复后才能看到
第一步,复制根目录下的 misc.php 文件为 misc_tag.php 文件,删除其中的
$discuz->reject_robot();(否则搜索引擎无法访问)。
注意:必须添加在“插件”页面的伪静态规则:
rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2
3 last;之前的任意位置,该规则使 tag标签页面 支持以网址 tag-标签编号-标签页数.html 访问指定标签页面
第三步,修改Discuz程序,使 tag链接 由原有的动态链接换为伪静态链接
[color=rgb(51, 51, 51)]1、打开 template/default/tag/tagitem.htm 模板文件,
[color=rgb(51, 51, 51)]将
<a class=\"xi2\" href=\"misc.php?mod=tag&id=$id&type=thread\">{lang more}...</a>修改为:
<a href=\"tag-$id-2.html\" class=\"xi2\" style=\"font-weight: bold;\">查看更多相关帖子 >>></a>将
<a class=\"xi2\" href=\"misc.php?mod=tag&id=$id&type=blog\">{lang more}...</a>修改为:
<a href=\"misc.php?mod=tag&id=$id&type=blog\" class=\"xi2\" style=\"font-weight: bold;\">查看更多相关日志 >>></a>将
<a href=\"misc.php?mod=tag\">{lang tag}</a>修改为:
<a href=\"tag.html\">{lang tag}</a>将
<a href=\"misc.php?mod=tag&id=$id\">$tagname</a>[color=rgb(51, 51, 51)]修改为:
<a href=\"tag-$id-1.html\">$tagname</a>将
<!--{loop $threadlist $thread}-->[color=rgb(51, 51, 51)]修改为
{eval $tiaoshu = 0}<!--{loop $threadlist $thread}-->{eval $tiaoshu ++;}将第一个
<!--{if empty($showtype)}-->修改为
<!--{if empty($showtype) && $tiaoshu >= 20}-->将
action=\"misc.php?mod=tag\"[color=rgb(51, 51, 51)]修改为
action=\"tag.html\"[color=rgb(51, 51, 51)]2、修改翻页按钮。打开 source/module/misc/misc_tag.php 文件,
将
$multipage = multi($count, $tpp, $page, \"misc.php?mod=tag&id=$tag[tagid]&type=thread\");[color=rgb(51, 51, 51)]修改为
$multipage = multi_guide($count, $tpp, $page, \"tag-$tag[tagid]\");打开 source/function/function_core 文件,在
function simplepage($num, $perpage, $curpage, $mpurl) {[color=rgb(51, 51, 51)]前面增加一段(定义multi_guide):
function multi_guide($num, $perpage, $curpage, $mpurl, $maxpages = 0, $page = 10, $autogoto = FALSE, $simple = FALSE, $jsfunc = FALSE) {
return $num > $perpage ? helper_page_guide::multi($num, $perpage, $curpage, $mpurl, $maxpages, $page, $autogoto, $simple, $jsfunc) : '';
}[color=rgb(51, 51, 51)]进入 source/class/helper/ 目录,将 helper_page.php 复制一份命名为 helper_page_guide.php 。并依次修改 helper_page_guide.php 文件中的以下部分:
[color=rgb(51, 51, 51)]将
helper_page[color=rgb(51, 51, 51)]修改为
helper_page_guide[color=rgb(51, 51, 51)](共两处,其中文件头注释中的那处无关紧要);将
$pagevar = 'page=';[color=rgb(51, 51, 51)]修改为
$pagevar = '-';[color=rgb(51, 51, 51)]将
$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);';[color=rgb(51, 51, 51)](此项操作使手动输入页码翻页时链接静态化);
将
return $mpurl.$separator.$pagevar.$page;[color=rgb(51, 51, 51)]修改为
return substr($mpurl, 0, -1).$separator.$pagevar.$page.'.html';[color=rgb(51, 51, 51)](翻页页码链接静态化)。
3、修改title。打开 source/module/misc/misc_tag.php 文件,
将
$navtitle = $tagname ? $taglang.' - '.$tagname : $taglang;修改为:
$navtitle = $tagname ? $tagname.$title_page.' - '.$taglang : $taglang;[color=rgb(51, 51, 51)]并在其前面加入一行:
if($_GET['page']) { $title_page = '(第'.$_GET['page'].'页)'; }[color=rgb(51, 51, 51)]4、使tag首页列出的tag链接和搜索按钮伪静态化。打开 template/default/tag/tag.htm 模板文件,
[color=rgb(51, 51, 51)]将
<a href=\"misc.php?mod=tag&id=$tag[tagid]\" title=\"$tag[tagname]\" target=\"_blank\" class=\"xi2\">$tag[tagname]</a>修改为:
<a href=\"tag-$tag[tagid]-1.html\" target=\"_blank\" class=\"xi2\">$tag[tagname]</a>[color=rgb(51, 51, 51)]将
action=\"misc.php?mod=tag\"修改为
action=\"tag.html\"[color=rgb(51, 51, 51)]、修改帖子页面上的tag链接,使其静态化。打开 template/default/forum/viewthread_node_body.htm 模板文件(部分模板可能在 viewthread_node.htm 文件中,自行查找),
[color=rgb(51, 51, 51)]将
misc.php?mod=tag&id=$var[0][color=rgb(51, 51, 51)]部分模板可能不只一处,搜索查找确认),修改为
tag-{echo intval($var[0])}-1.html6、修改标签不存在时返回标签首页的链接。
[color=rgb(51, 51, 51)]打开 source/language/tag/lang_template.php 文件,
[color=rgb(51, 51, 51)]将
<a href=\"misc.php?mod=tag\" title=\"返回标签首页\">返回标签首页</a>[color=rgb(51, 51, 51)]修改为
<a href=\"tag.html\" style=\"font-weight: bold;\">返回标签首页</a>
三.【discuz伪静态】之:帖子页“复制链接”“倒序/正序”伪静态
[color=rgb(51, 51, 51)]以discuz!3.4 + nginx为例!Apache,iis请自行转换!
[color=rgb(51, 51, 51)]
[color=rgb(51, 51, 51)]1、添加伪静态规则(以Nginx为例):
本部分内容设定了隐藏,需要回复后才能看到
依次为 复制链接、只看该作者、倒序看帖/正序看帖、只看大图、上一主题、下一主题、打印帖子 的伪静态规则
[color=rgb(51, 51, 51)]2、修改“复制链接”的链接。【复制链接伪静态有个投机取巧的方法文章最后分享给大家】打开 forum/viewthread.htm 模板文件,查找:
<a href=\"forum.php?mod=viewthread&tid=$_G[tid]$fromuid\" {if $fromuid}title=\"{lang share_url_copy_comment}\"{/if}>[{lang share_url_copy}]</a>替换为:
<!--{if !IS_ROBOT}--><a href=\"thread-$_G[tid]-<!--{if $_G['uid']}-->f$_G['uid']<!--{else}-->1-1<!--{/if}-->.html\" rel=\"nofollow\" {if $fromuid}title=\"{lang share_url_copy_comment}\"{/if}>[{lang share_url_copy}]</a><!--{/if}-->3、修改楼层号上复制楼层地址的链接。打开 forum/viewthread_node.htm (部分风格可能在viewthread_node_body.htm)模板文件,查找:
<a href=\"{if $post[first]}forum.php?mod=viewthread&tid=$_G[tid]$fromuid{else}forum.php?mod=redirect&goto=findpost&ptid=$_G[tid]&pid=$post[pid]$fromuid{/if}\" {if $fromuid}title=\"{lang share_url_copy_comment}\"{/if} id=\"postnum$post[pid]\">替换为:
<a href=\"{if $post[first]}forum.php?mod=viewthread&tid=$_G[tid]{else}thread-$_G[tid]-$page-1.html#pid$post[pid]{/if}\" title=\"点此复制本帖链接\" id=\"postnum$post[pid]\">4、“只看该作者”伪静态化。打开 forum/viewthread_node.htm (部分风格可能在viewthread_node_body.htm)模板文件,查找:
<span class=\"pipe\">|</span>
<!--{if !IS_ROBOT && !$_GET['authorid'] && !$_G['forum_thread']['archiveid']}-->
...
<!--{elseif !$_G['forum_thread']['archiveid']}-->
...
<!--{/if}-->将整个if段替换为:【别问我具体哪段,这点理解能力都没有那就不用改了】
<!--{if !IS_ROBOT && !$_GET['authorid'] && !$_G['forum_thread']['archiveid']}-->
<span class=\"pipe\">|</span>
<a href=\"thread-$post[tid]-1-u{$post[authorid]}.html\" rel=\"nofollow\">{lang thread_show_author}</a>
<!--{elseif !IS_ROBOT && !$_G['forum_thread']['archiveid']}-->
<span class=\"pipe\">|</span>
<a href=\"forum.php?mod=viewthread&tid=$post[tid]&page=$page\" rel=\"nofollow\">{lang thread_show_all}</a>
<!--{/if}-->5、“倒序/正序看帖”伪静态化。打开 forum/viewthread_node.htm (部分风格可能在viewthread_node_body.htm)模板文件,查找:
<!--{if $ordertype != 1}-->
...
<!--{else}-->
...
<!--{/if}-->将整个if段替换为:
<!--{if $ordertype != 1}-->
<span class=\"pipe show\">|</span><a href=\"thread-$_G[tid]-1-o1.html\" rel=\"nofollow\" class=\"show\">{lang post_descview}</a>
<!--{else}-->
<span class=\"pipe show\">|</span><a href=\"thread-$_G[tid]-1-o2.html\" rel=\"nofollow\" class=\"show\">{lang post_ascview}</a>
<!--{/if}-->[color=rgb(51, 51, 51)]6、“只看大图”和“打印”“上一主题/下一主题”链接伪静态化。
打开 forum/viewthread_node.htm 模板文件,查找
[color=rgb(51, 51, 51)]<a href=\"forum.php?mod=viewthread&tid=$_G[tid]&from=album\">{lang view_bigpic}</a>替换为:
[color=rgb(51, 51, 51)]<a href=\"thread-$_G[tid]-album.html\" rel=\"nofollow\"><font color=\"#336699\">相册模式</a>打开 forum/viewthread.htm 模板文件,查找:
[color=rgb(51, 51, 51)]forum.php?mod=viewthread&action=printable&tid=$_G[tid]替换为:
[color=rgb(51, 51, 51)]printable-$_G[tid].html查找:
[color=rgb(51, 51, 51)]forum.php?mod=redirect&goto=nextoldset&tid=$_G[tid]替换为:
[color=rgb(51, 51, 51)]thread-$_G[tid]-prev.html查找:
[color=rgb(51, 51, 51)]forum.php?mod=redirect&goto=nextnewset&tid=$_G[tid]替换为:
[color=rgb(51, 51, 51)]thread-$_G[tid]-next.html打开 source/module/forum/forum_redirect.php 文件,将:
[color=rgb(51, 51, 51)]if($next) {
dheader(\"Location: forum.php?mod=viewthread&tid=$next\");
} elseif($_GET['goto'] == 'nextnewset') {
showmessage('redirect_nextnewset_nonexistence');
} else {
showmessage('redirect_nextoldset_nonexistence');
}替换为:
[color=rgb(51, 51, 51)]if($next) {
dheader(\"Location: thread-$next-1-1.html\");
} elseif($_GET['goto'] == 'nextnewset') {
header('HTTP/1.1 404 Not Found');
showmessage('redirect_nextnewset_nonexistence');
} else {
header('HTTP/1.1 404 Not Found');
showmessage('redirect_nextoldset_nonexistence');
}7、帖子内容页翻页按钮伪静态化【默认伪静态规则为例改了默认规则可能会冲突,本站为了兼容【除了几个无关紧要的地方】全部改为了默认规则
[color=rgb(51, 51, 51)]打开 source/module/forum/forum_viewthread.php 文件,查找:
[color=rgb(51, 51, 51)]} else {
$_GET['viewpid'] = intval($_GET['viewpid']);在它上面加入:
[color=rgb(51, 51, 51)]$multipage_thread = multi_thread($_G['forum_thread']['replies'] + 1, $_G['ppp'], $page, 'thread-'.$_G['tid']);打开 source/function/function_core 文件,
[color=rgb(51, 51, 51)]在
[color=rgb(51, 51, 51)]function simplepage($num, $perpage, $curpage, $mpurl) {前面增加一段(定义multi_thread):
[color=rgb(51, 51, 51)]function multi_thread($num, $perpage, $curpage, $mpurl, $maxpages = 0, $page = 10, $autogoto = FALSE, $simple = FALSE, $jsfunc = FALSE) {
return $num > $perpage ? helper_page_thread::multi($num, $perpage, $curpage, $mpurl, $maxpages, $page, $autogoto, $simple, $jsfunc) : '';
}进入 source/class/helper/ 目录,将 helper_page.php 复制一份命名为 helper_page_thread.php 。并依次修改 helper_page_thread.php 文件中的以下部分:
将
[color=rgb(51, 51, 51)]helper_page修改为
[color=rgb(51, 51, 51)]helper_page_thread共两处,其中文件头注释中的那处无关紧要);
将
[color=rgb(51, 51, 51)]$pagevar = 'page=';修改为
[color=rgb(51, 51, 51)]$pagevar = '-';将
[color=rgb(51, 51, 51)]$jsurl = $mpurl.(strpos($mpurl, '{page}') !== false ? '\'.replace(\'{page}\', this.value == 1 ? \'\' : this.value)': $pagevar.'\'+this.value;').'; doane(event);';替换为:
[color=rgb(51, 51, 51)]$jsurl = substr($mpurl, 0, -1).(strpos($mpurl, '{page}') !== false ? '\'.replace(\'{page}\', this.value == 1 ? \'\' : this.value)': $pagevar.'\'+this.value').'+\''.$url_filter.'.html\'; doane(event);';在
[color=rgb(51, 51, 51)]public static function mpurl($mpurl, $pagevar, $page) {下新增:
[color=rgb(51, 51, 51)]if($_GET['authorid']) {
$url_filter = '-u'.$_GET['authorid'];
} elseif($_GET['ordertype'] == 1 || $_GET['ordertype'] == 2) {
$url_filter = '-o'.$_GET['ordertype'];
} else {
$url_filter = '-1';
}将
[color=rgb(51, 51, 51)]return $mpurl.$separator.$pagevar.$page;替换为:
[color=rgb(51, 51, 51)]return substr($mpurl, 0, -1).$separator.$pagevar.$page.$url_filter.'.html';打开 forum/viewthread.htm 模板文件,查找:
[color=rgb(51, 51, 51)]<div class=\"pgt\">$multipage</div>替换为
[color=rgb(51, 51, 51)]<div class=\"pgt\"><!--{if $_GET['highlight'] || $_GET['modthreadkey'] || $_GET['checkrush'] || $_G['forum_thread']['is_archived']}-->$multipage<!--{else}-->$multipage_thread<!--{/if}--></div>查找:
[color=rgb(51, 51, 51)]<div class=\"pgs mtm mbm cl\">将其下方的【这里有几处必须这样找】
[color=rgb(51, 51, 51)]$multipage替换为:
[color=rgb(51, 51, 51)]<!--{if $_GET['highlight'] || $_GET['modthreadkey'] || $_GET['checkrush'] || $_G['forum_thread']['is_archived']}-->$multipage<!--{else}-->$multipage_thread<!--{/if}-->8、“电梯直达”伪静态。
[color=rgb(51, 51, 51)]打开 forum/viewthread_node.htm 模板文件(部分风格有可能在 viewthread_node_body.htm 中),
查找:
[color=rgb(51, 51, 51)]<label class=\"z\">{lang thread_redirect_postno}</label>替换为:
[color=rgb(51, 51, 51)]<label class=\"z\">楼层跳转</label>打开 source/module/forum/forum_redirect.php 文件,查找:
[color=rgb(51, 51, 51)]header(\"HTTP/1.1 301 Moved Permanently\");
dheader(\"Location: forum.php?mod=viewthread&tid=$tid&page=$page$authoridurl$ordertypeurl\".(isset($_GET['modthreadkey']) && ($modthreadkey = modauthkey($tid)) ? \"&modthreadkey=$modthreadkey\": '').\"#pid$pid\");替换为:
[color=rgb(51, 51, 51)]$authoridurl2 = $authorid ? 'u'.$authorid : '';
$ordertypeurl2 = $ordertype ? 'o'.$ordertype : '';
if(!$authorid && !$ordertype) {
$noother = '1';
}
header(\"HTTP/1.1 301 Moved Permanently\");
if(!$modthreadkey) {
dheader(\"Location: thread-$tid-$page-\".$authoridurl2.$ordertypeurl2.$noother.\".html#pid$pid\");
} else {
dheader(\"Location: forum.php?mod=viewthread&tid=$tid&page=$page$authoridurl$ordertypeurl\".(isset($_GET['modthreadkey']) && ($modthreadkey = modauthkey($tid)) ? \"&modthreadkey=$modthreadkey\": '').\"#pid$pid\");
}查找:
[color=rgb(51, 51, 51)]if($ptid) {
header(\"HTTP/1.1 301 Moved Permanently\");
dheader(\"Location: forum.php?mod=viewthread&tid=$ptid\");替换为:
[color=rgb(51, 51, 51)]$authoridurl3 = $authorid ? 'u'.$authorid : '';
$ordertypeurl3 = $ordertype ? 'o'.$ordertype : '';
if(!$authorid && !$ordertype) {
$noother = '1';
}
if($ptid) {
header(\"HTTP/1.1 301 Moved Permanently\");
dheader(\"Location: thread-$ptid-1-\".$authoridurl3.$ordertypeurl3.$noother.\".html\");9、最后,在根目录 robots.txt 文件中添加:
[color=rgb(51, 51, 51)]]Disallow: /printable-*.html
Disallow: /thread-*f*.html
Disallow: /thread-*o*.html
Disallow: /thread-*u*.html
Disallow: /thread-*album.html
Disallow: /thread-*prev.html
Disallow: /thread-*next.html10.最后提示:本修改和演示站用的方法大致相同,不同的是部分地方简化了而已,各个版本文件代码有所出入,修改时间多注意就行了,本站是3.0升级上来的,找不到代码查找相关代码都可以找到!
四.【discuz伪静态】之“导读”页面伪静态优化
以discuz!3.4 + nginx为例!Apache,iis请自行转换!
[color=rgb(51, 51, 51)]1、增加伪静态规则,以Nginx为例:
本部分内容设定了隐藏,需要回复后才能看到
注意:必须放在
rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2
3 last;之前任一行,否则无法生效
[color=rgb(51, 51, 51)]2、让“导读”页面上的 最新XX 、抢沙发 等(除“我的帖子”)标签的链接伪静态化。打开 forum/guide 模板文件,将
<ul id=\"thread_types\" class=\"ttp bm cl\">后面的5个li行替换为:
<li $currentview['hot']><a href=\"latest-hot-1.html\">{lang guide_hot}</a></li>
<li $currentview['digest']><a href=\"latest-digest-1.html\">{lang guide_digest}</a></li>
<li $currentview['new']><a href=\"latest-new-1.html\">{lang guide_new}</a></li>
<li $currentview['newthread']><a href=\"latest-newthread-1.html\">{lang guide_newthread}</a></li>
<li $currentview['sofa']><a href=\"latest-sofa-1.html\">{lang guide_sofa}</a></li>将
{lang title}[color=rgb(51, 51, 51)]替换为:
[color=rgb(51, 51, 51)]<div class=\"tf\" style=\"padding-left:5px;\">主题列表</div>3、将底部翻页按钮前的“导读首页”改为“最新热门”,并将其链接伪静态化。打开 forum/guide 模板文件,将
[color=rgb(51, 51, 51)]<span class=\"pgb y\"><a href=\"forum.php?mod=guide\">{lang guide_index}</a></span>修改为
[color=rgb(51, 51, 51)]<span class=\"pgb y\"><a href=\"latest-hot-1.html\">最新热门</a></span>4、将面包屑导航条中的“导读”改为站名,并使后面的链接伪静态化。
打开 forum/guide 模板文件,将
[color=rgb(51, 51, 51)]<a href=\"./\" class=\"nvhm\" title=\"{lang homepage}\">$_G[setting][bbname]</a><!--{if helper_access::check_module('guide')}--><em>&#187;</em><a href=\"forum.php?
mod=guide&view=index\">{lang guide}</a><!--{/if}-->修改为
[color=rgb(51, 51, 51)]<a href=\"./\" class=\"nvhm\" title=\"{lang homepage}\"></a><em>&#187;</em><a href=\"./\">$_G[setting][bbname]</a>打开 source/module/forum/forum_guide 文件,将
[color=rgb(51, 51, 51)]<a href=\"forum.php?mod=guide&view='.$view.'\">替换为
[color=rgb(51, 51, 51)]<a href=\"latest-'.$view.'-1.html\">5、删除title中的“导读-”。打开 source/module/forum/forum_guide 文件,将
[color=rgb(51, 51, 51)]$navtitle = $lang['guide'].'-'.$lang['guide_'.$view];替换为
[color=rgb(51, 51, 51)]$navtitle = $lang['guide_'.$view].$title_page;并在前面增加一行
[color=rgb(51, 51, 51)]if($_GET['page'] > 1) { $title_page = '(第'.$_GET['page'].'页)'; }6、让“导读”页面上的翻页按钮静态化。
[color=rgb(51, 51, 51)]打开 source/module/forum/forum_guide 文件,将
[color=rgb(51, 51, 51)]$theurl = 'forum.php?mod=guide&view='.$view;剪切到其后 【不要问我剪切什么意思】
[color=rgb(51, 51, 51)]if($view == 'my') {里面的第一行,然后在
[color=rgb(51, 51, 51)]$data[$view] = get_guide_list($view, $start, $perpage);前面增加一行
[color=rgb(51, 51, 51)]$theurl = 'latest-'.$view;此项操作的目的是使“我的帖子”页面的翻页功能不受影响)。
[color=rgb(51, 51, 51)]接着将
[color=rgb(51, 51, 51)]$multipage = multi修改为
[color=rgb(51, 51, 51)]$multipage = multi_guide(将翻页按钮由标准改为自定义)。 【这步不推荐修改】
[color=rgb(51, 51, 51)]打开 source/function/function_core 文件,在
[color=rgb(51, 51, 51)]function simplepage($num, $perpage, $curpage, $mpurl) {前面增加一段(定义multi_guide):
[color=rgb(51, 51, 51)]function multi_guide($num, $perpage, $curpage, $mpurl, $maxpages = 0, $page = 10, $autogoto = FALSE, $simple = FALSE, $jsfunc = FALSE) {
return $num > $perpage ? helper_page_guide::multi($num, $perpage, $curpage, $mpurl, $maxpages, $page, $autogoto, $simple, $jsfunc) : '';
}进入 source/class/helper/ 目录,将 helper_page.php 复制一份命名为 helper_page_guide.php 。并依次修改 helper_page_guide.php 文件中的以下部分:
将 helper_page 修改为
[color=rgb(51, 51, 51)]helper_page_guide共两处,其中文件头注释中的那处无关紧要);将
[color=rgb(51, 51, 51)]$pagevar = 'page=';修改为
[color=rgb(51, 51, 51)]$pagevar = '-';将
[color=rgb(51, 51, 51)]$jsurl = $mpurl.(strpos($mpurl, '{page}') !== false ? '\'.replace(\'{page}\', this.value == 1 ? \'\' : this.value)': $pagevar.'\'+this.value;').'; doane(event);';修改为
[color=rgb(51, 51, 51)]$jsurl = substr($mpurl, 0, -1).(strpos($mpurl, '{page}') !== false ? '\'.replace(\'{page}\', this.value == 1 ? \'\' : this.value)': $pagevar.'\'+this.value').'+\'.html
\'; doane(event);';(此项操作使手动输入页码翻页时链接静态化);
[color=rgb(51, 51, 51)]将
[color=rgb(51, 51, 51)]return $mpurl.$separator.$pagevar.$page;修改为
[color=rgb(51, 51, 51)]return substr($mpurl, 0, -1).$separator.$pagevar.$page.'.html';(翻页页码链接静态化)
[color=rgb(51, 51, 51)]7、首页“最新回复”链接静态化。打开 forum/discuz 模板,将
[color=rgb(51, 51, 51)]forum.php?mod=guide&view=new替换为
[color=rgb(51, 51, 51)]latest-new-1.html8、将“我的帖子”标签链接加上nofollow,并且删除下拉菜单
打开 forum/guide 模板文件,将
[color=rgb(51, 51, 51)]<a id=\"filter_special\" href=\"forum.php?mod=guide&view=my\">这里好像有的文件没有最后那个符号
[color=rgb(51, 51, 51)]修改为
[color=rgb(51, 51, 51)]{if $_G['uid']}<a id=\"filter_special\" href=\"forum.php?mod=guide&view=my\">{else}<a href=\"forum.php?mod=guide&view=my\" rel=\"nofollow\">将
[color=rgb(51, 51, 51)]<!--{if !IS_ROBOT}-->修改为
[color=rgb(51, 51, 51)]<!--{if $_G['uid']}-->9、整理“导读”页面“rss订阅”的代码。打开 source/module/forum/forum_guide 文件
[color=rgb(51, 51, 51)]将
[color=rgb(51, 51, 51)]\" <link>{$_G[siteurl]}forum.php?mod=guide&view=$view</link>\n\".修改为
[color=rgb(51, 51, 51)]\" <link>{$_G[siteurl]}latest-$view-1.html</link>\n\".将
[color=rgb(51, 51, 51)]Copyright(C) {$_G[setting][bbname]}替换为
[color=rgb(51, 51, 51)]Copyright (C) 建站年份-当前年份 网址将
[color=rgb(51, 51, 51)]Discuz! Board by Comsenz Inc.修改为
[color=rgb(51, 51, 51)]{$_G[setting][bbname]}将
[color=rgb(51, 51, 51)]$filename = $_G['siteurl'].$_G['setting']['attachurl'].'forum/'.$attachfile;修改为
[color=rgb(51, 51, 51)]$filename = $_G['setting']['attachurl'].'forum/'.$attachfile;10、去掉最后回复时间及其作者的链接,给主帖作者链接加上nofollow。打开 forum/guide_list_row 模板,
将
[color=rgb(51, 51, 51)]<td class=\"num\"><a href=\"forum.php?mod=viewthread&tid=$thread[tid]&extra=$extra\" class=\"xi2\">$thread[replies]</a><em><!--{if $thread['isgroup'] != 1}-->$thread[views]段替换为
[color=rgb(51, 51, 51)]<td class=\"by\">
<cite><!--{if $thread['lastposter']}-->$thread[lastposter]<!--{else}-->$_G[setting][anonymoustext]<!--{/if}--></cite>
<em>$thread[lastpost]</em>
</td>将
[color=rgb(51, 51, 51)][font=Ar

遇到问题了 顺着杆子找来的 看对不对口