|
|
本帖最后由 冰糖 于 2018-8-25 17:15 编辑
昨天看到有朋友需要,然后今天抽时间整理了一下
要提醒:修改前请备份源文件,如果发现修改后进入页面空白,请检查代码是否修改正确!】
由于这个是把重要的代码全部【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.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 模板
将
替换为
- <!--{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 (共两处,其中文件头注释中的那处无关紧要);
将
修改为
将
- $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>[/color][/size][/font]
- 主题筛选:
- [/color][/size][/font][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> [/color][/size][/font]
- 排序:
- <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>
复制代码 将
替换为
- <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>
复制代码 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请自行转换!
我记得好像从Discuz X3.2开始默认是禁止搜索引擎访问 misc.php 文件的,因此 tag 不会被收录。
我们可以将 tag 网址伪静态化,这样不仅使 tag 网址看上去更规范美观,还使 tag 页面可以被百度收录。
1、添加伪静态规则(以Nginx为例):
第一步,复制根目录下的 misc.php 文件为 misc_tag.php 文件,删除其中的
(否则搜索引擎无法访问)。
注意:必须添加在“插件”页面的伪静态规则:
- rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3 last;
复制代码 之前的任意位置,该规则使 tag标签页面 支持以网址 tag-标签编号-标签页数.html 访问指定标签页面
第三步,修改Discuz程序,使 tag链接 由原有的动态链接换为伪静态链接
1、打开 template/default/tag/tagitem.htm 模板文件,
将
- <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>
复制代码 修改为:
- <a href="tag-$id-1.html">$tagname</a>
复制代码 将
- <!--{loop $threadlist $thread}-->
复制代码 修改为
- {eval $tiaoshu = 0}<!--{loop $threadlist $thread}-->{eval $tiaoshu ++;}
复制代码 将第一个
- <!--{if empty($showtype)}-->
复制代码 修改为
- <!--{if empty($showtype) && $tiaoshu >= 20}-->
复制代码 将
- action="misc.php?mod=tag"
复制代码 修改为
2、修改翻页按钮。打开 source/module/misc/misc_tag.php 文件,
将
- $multipage = multi($count, $tpp, $page, "misc.php?mod=tag&id=$tag[tagid]&type=thread");
复制代码 修改为
- $multipage = multi_guide($count, $tpp, $page, "tag-$tag[tagid]");
复制代码 打开 source/function/function_core 文件,在
- function simplepage($num, $perpage, $curpage, $mpurl) {
复制代码 前面增加一段(定义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) : '';
- }
复制代码 进入 source/class/helper/ 目录,将 helper_page.php 复制一份命名为 helper_page_guide.php 。并依次修改 helper_page_guide.php 文件中的以下部分:
将
修改为
(共两处,其中文件头注释中的那处无关紧要);将
修改为
将
- $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';
复制代码 (翻页页码链接静态化)。
3、修改title。打开 source/module/misc/misc_tag.php 文件,
将
- $navtitle = $tagname ? $taglang.' - '.$tagname : $taglang;
复制代码 修改为:
- $navtitle = $tagname ? $tagname.$title_page.' - '.$taglang : $taglang;
复制代码 并在其前面加入一行:
- if($_GET['page']) { $title_page = '(第'.$_GET['page'].'页)'; }
复制代码 4、使tag首页列出的tag链接和搜索按钮伪静态化。打开 template/default/tag/tag.htm 模板文件,
将
- <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>
复制代码 将
- action="misc.php?mod=tag"
复制代码 修改为
、修改帖子页面上的tag链接,使其静态化。打开 template/default/forum/viewthread_node_body.htm 模板文件(部分模板可能在 viewthread_node.htm 文件中,自行查找),
将
- misc.php?mod=tag&id=$var[0]
复制代码 部分模板可能不只一处,搜索查找确认),修改为
- tag-{echo intval($var[0])}-1.html
复制代码 6、修改标签不存在时返回标签首页的链接。
打开 source/language/tag/lang_template.php 文件,
将
- <a href="misc.php?mod=tag" title="返回标签首页">返回标签首页</a>
复制代码 修改为
- <a href="tag.html" style="font-weight: bold;">返回标签首页</a>
复制代码
三.【discuz伪静态】之:帖子页“复制链接”“倒序/正序”伪静态
以discuz!3.4 + nginx为例!Apache,iis请自行转换!
1、添加伪静态规则(以Nginx为例):
依次为 复制链接、只看该作者、倒序看帖/正序看帖、只看大图、上一主题、下一主题、打印帖子 的伪静态规则
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}-->
复制代码 6、“只看大图”和“打印”“上一主题/下一主题”链接伪静态化。
打开 forum/viewthread_node.htm 模板文件,查找
- <a href="forum.php?mod=viewthread&tid=$_G[tid]&from=album">{lang view_bigpic}</a>
复制代码 替换为:
- <a href="thread-$_G[tid]-album.html" rel="nofollow"><font color="#336699">相册模式</a>
复制代码 打开 forum/viewthread.htm 模板文件,查找:
- forum.php?mod=viewthread&action=printable&tid=$_G[tid]
复制代码 替换为:
查找:
- forum.php?mod=redirect&goto=nextoldset&tid=$_G[tid]
复制代码 替换为:
- thread-$_G[tid]-prev.html
复制代码 查找:
- forum.php?mod=redirect&goto=nextnewset&tid=$_G[tid]
复制代码 替换为:
- thread-$_G[tid]-next.html
复制代码 打开 source/module/forum/forum_redirect.php 文件,将:
- if($next) {
- dheader("Location: forum.php?mod=viewthread&tid=$next");
- } elseif($_GET['goto'] == 'nextnewset') {
- showmessage('redirect_nextnewset_nonexistence');
- } else {
- showmessage('redirect_nextoldset_nonexistence');
- }
复制代码 替换为:
- 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、帖子内容页翻页按钮伪静态化【默认伪静态规则为例改了默认规则可能会冲突,本站为了兼容【除了几个无关紧要的地方】全部改为了默认规则
打开 source/module/forum/forum_viewthread.php 文件,查找:
- } else {
- $_GET['viewpid'] = intval($_GET['viewpid']);
复制代码 在它上面加入:
- $multipage_thread = multi_thread($_G['forum_thread']['replies'] + 1, $_G['ppp'], $page, 'thread-'.$_G['tid']);
复制代码 打开 source/function/function_core 文件,
在
- function simplepage($num, $perpage, $curpage, $mpurl) {
复制代码 前面增加一段(定义multi_thread):
- 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 文件中的以下部分:
将
修改为
共两处,其中文件头注释中的那处无关紧要);
将
修改为
将
- $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').'+\''.$url_filter.'.html\'; doane(event);';
复制代码 在
- public static function mpurl($mpurl, $pagevar, $page) {
复制代码 下新增:
- if($_GET['authorid']) {
- $url_filter = '-u'.$_GET['authorid'];
- } elseif($_GET['ordertype'] == 1 || $_GET['ordertype'] == 2) {
- $url_filter = '-o'.$_GET['ordertype'];
- } else {
- $url_filter = '-1';
- }
复制代码 将
- return $mpurl.$separator.$pagevar.$page;
复制代码 替换为:
- return substr($mpurl, 0, -1).$separator.$pagevar.$page.$url_filter.'.html';
复制代码 打开 forum/viewthread.htm 模板文件,查找:
- <div class="pgt">$multipage</div>
复制代码 替换为
- <div class="pgt"><!--{if $_GET['highlight'] || $_GET['modthreadkey'] || $_GET['checkrush'] || $_G['forum_thread']['is_archived']}-->$multipage<!--{else}-->$multipage_thread<!--{/if}--></div>
复制代码 查找:
- <div class="pgs mtm mbm cl">
复制代码 将其下方的【这里有几处必须这样找】
替换为:
- <!--{if $_GET['highlight'] || $_GET['modthreadkey'] || $_GET['checkrush'] || $_G['forum_thread']['is_archived']}-->$multipage<!--{else}-->$multipage_thread<!--{/if}-->
复制代码 8、“电梯直达”伪静态。
打开 forum/viewthread_node.htm 模板文件(部分风格有可能在 viewthread_node_body.htm 中),
查找:
- <label class="z">{lang thread_redirect_postno}</label>
复制代码 替换为:
- <label class="z">楼层跳转</label>
复制代码 打开 source/module/forum/forum_redirect.php 文件,查找:
- 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");
复制代码 替换为:
- $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");
- }
复制代码 查找:
- if($ptid) {
- header("HTTP/1.1 301 Moved Permanently");
- dheader("Location: forum.php?mod=viewthread&tid=$ptid");
复制代码 替换为:
- $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 文件中添加:
- ]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.html
复制代码 10.最后提示:本修改和演示站用的方法大致相同,不同的是部分地方简化了而已,各个版本文件代码有所出入,修改时间多注意就行了,本站是3.0升级上来的,找不到代码查找相关代码都可以找到!
四.【discuz伪静态】之“导读”页面伪静态优化
以discuz!3.4 + nginx为例!Apache,iis请自行转换!
1、增加伪静态规则,以Nginx为例:
注意:必须放在
- rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3 last;
复制代码 之前任一行,否则无法生效
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>
复制代码 将
替换为:
- <div class="tf" style="padding-left:5px;">主题列表</div>
复制代码 3、将底部翻页按钮前的“导读首页”改为“最新热门”,并将其链接伪静态化。打开 forum/guide 模板文件,将
- <span class="pgb y"><a href="forum.php?mod=guide">{lang guide_index}</a></span>
复制代码 修改为
- <span class="pgb y"><a href="latest-hot-1.html">最新热门</a></span>
复制代码 4、将面包屑导航条中的“导读”改为站名,并使后面的链接伪静态化。
打开 forum/guide 模板文件,将
- <a href="./" class="nvhm" title="{lang homepage}">$_G[setting][bbname]</a><!--{if helper_access::check_module('guide')}--><em>»</em><a href="forum.php?
- mod=guide&view=index">{lang guide}</a><!--{/if}-->
复制代码 修改为
- <a href="./" class="nvhm" title="{lang homepage}"></a><em>»</em><a href="./">$_G[setting][bbname]</a>
复制代码 打开 source/module/forum/forum_guide 文件,将
- <a href="forum.php?mod=guide&view='.$view.'">
复制代码 替换为
- <a href="latest-'.$view.'-1.html">
复制代码 5、删除title中的“导读-”。打开 source/module/forum/forum_guide 文件,将
- $navtitle = $lang['guide'].'-'.$lang['guide_'.$view];
复制代码 替换为
- $navtitle = $lang['guide_'.$view].$title_page;
复制代码 并在前面增加一行
- if($_GET['page'] > 1) { $title_page = '(第'.$_GET['page'].'页)'; }
复制代码 6、让“导读”页面上的翻页按钮静态化。
打开 source/module/forum/forum_guide 文件,将
- $theurl = 'forum.php?mod=guide&view='.$view;
复制代码 剪切到其后 【不要问我剪切什么意思】
里面的第一行,然后在
- $data[$view] = get_guide_list($view, $start, $perpage);
复制代码 前面增加一行
- $theurl = 'latest-'.$view;
复制代码 此项操作的目的是使“我的帖子”页面的翻页功能不受影响)。
接着将
修改为
(将翻页按钮由标准改为自定义)。 【这步不推荐修改】
打开 source/function/function_core 文件,在
- function simplepage($num, $perpage, $curpage, $mpurl) {
复制代码 前面增加一段(定义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) : '';
- }
复制代码 进入 source/class/helper/ 目录,将 helper_page.php 复制一份命名为 helper_page_guide.php 。并依次修改 helper_page_guide.php 文件中的以下部分:
将 helper_page 修改为
共两处,其中文件头注释中的那处无关紧要);将
修改为
将
- $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';
复制代码 (翻页页码链接静态化)
7、首页“最新回复”链接静态化。打开 forum/discuz 模板,将
- forum.php?mod=guide&view=new
复制代码 替换为
8、将“我的帖子”标签链接加上nofollow,并且删除下拉菜单
打开 forum/guide 模板文件,将
- <a id="filter_special" href="forum.php?mod=guide&view=my">
复制代码 这里好像有的文件没有最后那个符号
修改为
- {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">
复制代码 将
修改为
9、整理“导读”页面“rss订阅”的代码。打开 source/module/forum/forum_guide 文件
将
- " <link>{$_G[siteurl]}forum.php?mod=guide&view=$view</link>\n".
复制代码 修改为
- " <link>{$_G[siteurl]}latest-$view-1.html</link>\n".
复制代码 将
- Copyright(C) {$_G[setting][bbname]}
复制代码 替换为
- Copyright (C) 建站年份-当前年份 网址
复制代码 将
- Discuz! Board by Comsenz Inc.
复制代码 修改为
将
- $filename = $_G['siteurl'].$_G['setting']['attachurl'].'forum/'.$attachfile;
复制代码 修改为
- $filename = $_G['setting']['attachurl'].'forum/'.$attachfile;
复制代码 10、去掉最后回复时间及其作者的链接,给主帖作者链接加上nofollow。打开 forum/guide_list_row 模板,
将
- <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]
复制代码 段替换为
- <td class="by">
- <cite><!--{if $thread['lastposter']}-->$thread[lastposter]<!--{else}-->$_G[setting][anonymoustext]<!--{/if}--></cite>
- <em>$thread[lastpost]</em>
- </td>
复制代码 将
- <a href="home.php?mod=space&uid=$thread[authorid]" c="1">
复制代码 修改为
- <a href="home.php?mod=space&uid=$thread[authorid]" rel="nofollow" target="_blank" c="1">
复制代码 11、删除标题前面图标的链接。打开 forum/guide_list_row 模板,删除
- <a href="forum.php?mod=viewthread&tid=$thread[icontid]&{if $_GET['archiveid']}
复制代码 起至- {lang target_blank}" target="_blank">
复制代码 的整段代码,
同时将随后最近一个 <!--{/if}--> 后面的 </a> 删除
12、删除回复数的链接。同样是 forum/guide_list_row 模板,将
- <a href="forum.php?mod=viewthread&tid=$thread[tid]&extra=$extra" class="xi2">$thread[replies]</a>
复制代码 替换为
9-12步其实没什么用,不推荐修改
五.Discuz X3.2/3.4 分区 gid 完美伪静态方法 Apache/Nginx
分区伪静态规则 Nginx伪静态规则: - rewrite ^([^\.]*)/forum-([0-9]+)\.html$ $1/forum.php?gid=$2 last;
复制代码Apache伪静态规则: - RewriteCond %{QUERY_STRING} ^(.*)$
- RewriteRule ^forum-(\w+)\.html$ forum.php?gid=$1 [L]
复制代码论坛首页:打开 template/default/forum/discuz.htm 将 替换为: 版块页:打开 source/module/forum/forum_forumdisplay.php 搜索: - Location: forum.php?gid=$_G[fid]
复制代码替换为: - Location: forum-$_G[fid].html
复制代码搜索: - forum.php?gid='.$forum_up['fid'].'
复制代码替换为: - forum-'.$forum_up['fid'].'.html
复制代码搜索: - forum.php?gid='.$forum_top['fid'].'
复制代码替换为: - forum-'.$forum_top['fid'].'.html
复制代码帖子页:打开 source/module/forum/forum_viewthread.php 搜索: 替换为: - ? 'forum-'.$fup.'.html' :
复制代码这里有两个地方需要修改。 发帖页:打开 source/module/forum/forum_post.php 搜索: - ? 'forum.php?gid='.$fup :
复制代码替换为: - ? 'forum-'.$fup.'.html' :
复制代码这里也有两个地方需要修改。
|
评分
-
查看全部评分
|