discuz论坛全站关键标签伪静态问题

admin8年前 (2016-02-29)网站设计455

当我们采用discuz论坛程序建设的网站伪静态后,在论坛版块里面点击帖子转到帖子内容页是伪静态的地址。但是当我们点击论坛首页上面出现的“最后发表”“最新发表”等帖子标题时转到的具体的帖子内容页后发现帖子的地址却是动态地址:siteAddress/forum.php?mod=redirect&tid=$forum数字&goto=lastpost。不信你可以去随便找几个采用discuz建立的网站看看,包括discuz官方论坛也是这样的。

该方案不仅可以解决这个问题,而且还能把这个链接做活,以后无论论坛是改成伪静态还是动态,这里自动更换,无需再修改模板源代码,一次替换,终身受益。哈哈,不多说了,很简单,1步就搞定。

下面是具体的解决方案:论坛版块横排:在template\default\forum\discuz.htm页面    查找:forum.php?mod=redirect&tid=$forum[lastpost][tid]&goto=lastpost#lastpost    把这个替换为:    forum.php?mod=viewthread&tid=$forum[lastpost][tid]    就这么简单,比以前的改成静态的比如 thread-$forum[lastpost][tid]-1-1.html 要好得多,因为这个是死的,我的方法是活的,哈哈,万能的哦。    Discuz X2.0论坛帖“复制链接”伪静态实现方法 打开 /template/default/forum/viewthread.htm 在大约200行左右找到以下代码: forum.php?mod=viewthread&tid=$_G[tid]$fromuid 换成 forum.php?mod=viewthread&tid=$_G[tid] 就可以了
1、添加伪静态规则(以Nginx为例):

  1. rewrite ^([^\.]*)/thread-([0-9]+)-f([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&fromuid=$3 last;

  2. rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-u([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&authorid=$4&page=$3 last;

  3. rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-o([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&ordertype=$4&page=$3 last;

  4. rewrite ^([^\.]*)/thread-([1-9][0-9]*)-album\.html$ $1/forum.php?mod=viewthread&tid=$2&from=album last;

  5. rewrite ^([^\.]*)/forum-([1-9][0-9]*)-last\.html$ $1/forum.php?mod=redirect&goto=nextoldset&tid=$2 last;

  6. rewrite ^([^\.]*)/forum-([1-9][0-9]*)-next\.html$ $1/forum.php?mod=redirect&goto=nextnewset&tid=$2 last;

  7. rewrite ^([^\.]*)/printable-([0-9]+)\.html$ $1/forum.php?mod=viewthread&action=printable&tid=$2 last;

依次为 复制链接、只看该作者、倒序看帖/正序看帖、只看大图、上一主题、下一主题、打印帖子 的伪静态规则。

2、修改“复制链接”的链接。打开 forum/viewthread.htm 模板文件,查找:

  1. <a href="forum.php?mod=viewthread&tid=$_G[tid]$fromuid" {if $fromuid}title="{lang share_url_copy_comment}"{/if}>[{lang share_url_copy}]</a>

替换为:

  1. <!--{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)模板文件,查找:

  1. <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]">

替换为:

  1. <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)模板文件,查找:

  1. <span class="pipe">|</span>

  2. <!--{if !IS_ROBOT && !$_GET['authorid'] && !$_G['forum_thread']['archiveid']}-->

  3. ...

  4. <!--{elseif !$_G['forum_thread']['archiveid']}-->

  5. ...

  6. <!--{/if}-->

将整个if段替换为:

  1. <!--{if !IS_ROBOT && !$_GET['authorid'] && !$_G['forum_thread']['archiveid']}-->

  2. <span class="pipe">|</span>

  3. <a href="thread-$post[tid]-1-u{$post[authorid]}.html" rel="nofollow">{lang thread_show_author}</a>

  4. <!--{elseif !IS_ROBOT && !$_G['forum_thread']['archiveid']}-->

  5. <span class="pipe">|</span>

  6. <a href="forum.php?mod=viewthread&tid=$post[tid]&page=$page" rel="nofollow">{lang thread_show_all}</a>

  7. <!--{/if}-->


5、“倒序/正序看帖”伪静态化。打开 forum/viewthread_node.htm (或可能为viewthread_node_body.htm)模板文件,查找:

  1. <!--{if $ordertype != 1}-->

  2. ...

  3. <!--{else}-->

  4. ...

  5. <!--{/if}-->

将整个if段替换为:

  1. <!--{if $ordertype != 1}-->

  2. <span class="pipe show">|</span><a href="thread-$_G[tid]-1-o1.html" rel="nofollow" class="show">{lang post_descview}</a>;

  3. <!--{else}-->

  4. <span class="pipe show">|</span><a href="thread-$_G[tid]-1-o2.html" rel="nofollow" class="show">{lang post_ascview}</a>

  5. <!--{/if}-->


6、“只看大图”和“打印”“上一主题/下一主题”链接伪静态化。
打开 forum/viewthread_node.htm 模板文件,查找

  1. <a href="forum.php?mod=viewthread&tid=$_G[tid]&from=album">{lang view_bigpic}</a>

替换为:  

  1. <a href="thread-$_G[tid]-album.html" rel="nofollow"><font color="#336699">相册模式</a>


打开 forum/viewthread.htm 模板文件,查找:

  1. forum.php?mod=viewthread&action=printable&tid=$_G[tid]

替换为:

  1. printable-$_G[tid].html


查找:

  1. forum.php?mod=redirect&goto=nextoldset&tid=$_G[tid]

替换为:

  1. thread-$_G[tid]-prev.html


超找:

  1. forum.php?mod=redirect&goto=nextnewset&tid=$_G[tid]

替换为:

  1. thread-$_G[tid]-next.html


打开 source/module/forum/forum_redirect.php 文件,将:

  1. if($next) {5

  2. dheader("Location: forum.php?mod=viewthread&tid=$next");(

  3. } elseif($_GET['goto'] == 'nextnewset') {4

  4. showmessage('redirect_nextnewset_nonexistence');

  5. } else {

  6. showmessage('redirect_nextoldset_nonexistence');

  7. }

替换为:

  1. if($next) {

  2. dheader("Location: thread-$next-1-1.html");

  3. } elseif($_GET['goto'] == 'nextnewset') {

  4. header('HTTP/1.1 404 Not Found');

  5. showmessage('redirect_nextnewset_nonexistence');:

  6. } else {

  7. header('HTTP/1.1 404 Not Found');

  8. showmessage('redirect_nextoldset_nonexistence');

  9. }


7、帖子内容页翻页按钮伪静态化。
打开 source/module/forum/forum_viewthread.php 文件,查找:

  1. } else {

  2. $_GET['viewpid'] = intval($_GET['viewpid']);

在它上面加入:

  1. $multipage_thread = multi_thread($_G['forum_thread']['replies'] + 1, $_G['ppp'], $page, 'thread-'.$_G['tid']);


打开 source/function/function_core 文件

  1. function simplepage($num, $perpage, $curpage, $mpurl) {

前面增加一段(定义multi_thread):

  1. function multi_thread($num, $perpage, $curpage, $mpurl, $maxpages = 0, $page = 10, $autogoto = FALSE, $simple = FALSE, $jsfunc = FALSE) {

  2. return $num > $perpage ? helper_page_thread::multi($num, $perpage, $curpage, $mpurl, $maxpages, $page, $autogoto, $simple, $jsfunc) : '';

  3. }


进入 source/class/helper/ 目录,将 helper_page.php 复制一份命名为 helper_page_thread.php 。并依次修改 helper_page_thread.php 文件中的以下部分:

  1. helper_page

修改为

  1. helper_page_thread


(共两处,其中文件头注释中的那处无关紧要);

  1. $pagevar = 'page=';

修改为

  1. $pagevar = '-';



  1. $wml = defined('IN_MOBILE') && IN_MOBILE == 3;

  2. 前面新增:

  3. [code]if($_GET['authorid']) {

  4. $url_filter = '-u'.$_GET['authorid'];

  5. } elseif($_GET['ordertype'] == 1 || $_GET['ordertype'] == 2) {

  6. $url_filter = '-o'.$_GET['ordertype'];

  7. } else {

  8. $url_filter = '-1';

  9. }



  1. $jsurl = $mpurl.(strpos($mpurl, '{page}') !== false ? '\'.replace(\'{page}\', this.value == 1 ? \'\' : this.value)': $pagevar.'\'+this.value;').'; doane(event);';

替换为:

  1. $jsurl = substr($mpurl, 0, -1).(strpos($mpurl, '{page}') !== false ? '\'.replace(\'{page}\', this.value == 1 ? \'\' : this.value)': $pagevar.'\'+this.value').'+\''.$url_filter.'.html\'; doane(event);';



  1. public static function mpurl($mpurl, $pagevar, $page) {

下新增:

  1. if($_GET['authorid']) {

  2. $url_filter = '-u'.$_GET['authorid'];

  3. } elseif($_GET['ordertype'] == 1 || $_GET['ordertype'] == 2) {

  4. $url_filter = '-o'.$_GET['ordertype'];

  5. } else {

  6. $url_filter = '-1';

  7. }



  1. return $mpurl.$separator.$pagevar.$page;

替换为:

  1. return substr($mpurl, 0, -1).$separator.$pagevar.$page.$url_filter.'.html';


打开 forum/viewthread.htm 模板文件,查找:

  1. <div class="pgt">$multipage</div>

替换为  

  1. <div class="pgt"><!--{if $_GET['highlight'] || $_GET['modthreadkey'] || $_GET['checkrush'] || $_G['forum_thread']['is_archived']}-->$multipage<!--{else}-->$multipage_thread<!--{/if}--></div>


查找:

  1. <div class="pgs mtm mbm cl">

将其下方的

  1. $multipage

的替换为:

  1. <!--{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 中)
查找:

  1. <label class="z">{lang thread_redirect_postno}</label>

  2. <input type="text" class="px p_fre z" size="2" title="{lang thread_redirect_postno_tips}" />

替换为:

  1. <label class="z">楼层跳转</label>

  2. <input type="text" class="px p_fre z" size="2" title="{lang thread_redirect_postno_tips}" />


打开 source/module/forum/forum_redirect.php 文件,查找:

  1. header("HTTP/1.1 301 Moved Permanently");

  2. dheader("Location: forum.php?mod=viewthread&tid=$tid&page=$page$authoridurl$ordertypeurl".(isset($_GET['modthreadkey']) && ($modthreadkey = modauthkey($tid)) ? "&modthreadkey=$modthreadkey": '')."#pid$pid");

替换为:

  1. $authoridurl2 = $authorid ? 'u'.$authorid : '';

  2. $ordertypeurl2 = $ordertype ? 'o'.$ordertype : '';#

  3. if(!$authorid && !$ordertype) {

  4. $noother = '1';

  5. }

  6. header("HTTP/1.1 301 Moved Permanently");

  7. if(!$modthreadkey) {

  8. dheader("Location: thread-$tid-$page-".$authoridurl2.$ordertypeurl2.$noother.".html#pid$pid");

  9. } else {

  10. dheader("Location: forum.php?mod=viewthread&tid=$tid&page=$page$authoridurl$ordertypeurl".(isset($_GET['modthreadkey']) && ($modthreadkey = modauthkey($tid)) ? "&modthreadkey=$modthreadkey": '')."#pid$pid");

  11. }


查找:

  1. if($ptid) {

  2. header("HTTP/1.1 301 Moved Permanently");

  3. dheader("Location: forum.php?mod=viewthread&tid=$ptid");

替换为:

  1. $authoridurl3 = $authorid ? 'u'.$authorid : '';

  2. $ordertypeurl3 = $ordertype ? 'o'.$ordertype : '';

  3. if(!$authorid && !$ordertype) {

  4. $noother = '1';6

  5. }

  6. if($ptid) {

  7. header("HTTP/1.1 301 Moved Permanently");

  8. dheader("Location: thread-$ptid-1-".$authoridurl3.$ordertypeurl3.$noother.".html");


9、最后,在根目录 robots.txt 文件中添加:

  1. Disallow: /printable-*.html

  2. Disallow: /thread-*f*.html

  3. Disallow: /thread-*o*.html

  4. Disallow: /thread-*u*.html

  5. Disallow: /thread-*album.html

  6. Disallow: /thread-*prev.html

  7. Disallow: /thread-*next.html

相关文章

代码实现百度的自动Ping服务

代码实现百度的自动Ping服务

为了加快网站页面收录,seo人员可通过网站外链建设来实现,seo外链专员就是做这个工作的。还有一种方式是向搜索引擎提交网站的URL,这就是百度的Ping服务。ping是基于XML_RPC标准协议的更新...

Serializable引起System.StackOverFlowException

Serializable引起System.StackOverFlowException

场景:web client + webapi,涉及到对象序列化传输的对象使用Serializable属性时的调试效果,出现堆栈溢出,iisexpress也挂掉了。出现这个问题,一般也难找出问题所在,但...

asp版zblog文章分类页设计处理

asp版zblog文章分类页设计处理

zblog是一款非常优秀的cms程序,由RainbowSoft Studio团队开发,因其小巧强大而广泛用于博客程序的使用,目前有asp和php两个版本。这里以asp版本的zblog程序为例,讲解zb...

zblog分类页高级伪静态

上一篇给zblog分类页的标题加上了页码,以利于网站SEO,这次要解决的是zblog分类页伪静态时一个缺点——URL分类目录不统一,对搜索引擎也是不友好的。作为网站建设者,一个对代码敏感的程序开发人员...

discuzX单页制作

一般单页效果设计ycy.php 放在dz的根目录<?php            ...

网站安全之防止重放攻击

网站安全之防止重放攻击

网站设计中有一项——网站安全是需要开发人员去考虑的,今天要讲的是网站安全中的重放攻击。什么是重放攻击?如何防止重放攻击?重放攻击(Replay Attacks)又称重播攻击、回放攻击或新鲜性攻击(Fr...

评论列表

SEO博客
8年前 (2016-03-07)

作为刚刚进入SEO公司实习的优化专员,您的文章很值的我去学习,谢谢您提供了这么好的平台!我自己也建立了一个SEO博客 www.wequwe.com 也希望像您一样,分享有价值的东西!

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。