给discuz加canonical URL标签,规范化网址

已有 36 次阅读2025-11-11 14:37 |个人分类:站长日志

viewthread.php、forumdisplay.php、archiver添加 canonical URL 标签的方法,以解决重复网页问题,集中权重。

一,给viewthread.php页加canonical URL

可以发现这种动态的链接形式最多了,有不同的参数但内容一样,当然现在的SE能够处理这些问题,但但很难判断首选显示URL方式,或者当他们都有返回链接时,不能集中权重。为了解决类似的重复网页问题,googel,yahoo,live,ask.com都宣布支持一个新的标签属性,以把链接和权重都集中到一个首先的URL上。

1.给viewthread.php加canonical URL标签,指定帖子的静态地址为首选版本。

修改viewthread.php文件,在$page = max($page, 1);上面(程序调用包含文件结束),加一行$extrahead .='<link rel="canonical" href="thread-' .$tid. '-1-1.html" />';

2.给打印页加canonical tag
虽然打印页viewthread.php?action=printable.....也是调过这个程序生成数据,但用了不同的模板,要把变量$extrahead 加进去,修改tmplates\default\viewthread_printable.htm
在<head>部分<title>的下面加一行: $extrahead

二.给forumdisplay.php加canonical tag
在include template('forumdisplay');上加一行:
$extrahead .='<link rel="canonical" href="forum-' .$fid. '-' .$page. '.html" />';

三.为archiver页加link canonical标签

1.修改archiver/index.php:在global $boardurl, $_DCACHE, $charset, $navtitle, $headerbanner, $headernav;行下加一行:global $extrahead;
在<meta http-equiv="Content-Type" content="text/html; charset={$charset}" />
行下加一行:$extrahead

2.修改archiver\include\thread.inc.php:此文件中有两个showheader();,在第二个的上面加一行:$extrahead .='<link rel="canonical" href="thread-' .$tid. '-1-1.html" />';

四.将archiver内容页最下的“本看完整版本”链接改为静态形式
修改archiver/include/thread.inc.php,将 "viewthread.php?tid=$tid"替换为"thread-{$tid}-1-1.html"

如果您是以动态URL形式为首先版本,上述相应位置应替换为如下语句:
$extrahead .='<link rel="canonical" href="viewthread.php?tid=' .$tid. '" />';


路过

雷人

握手

鲜花

鸡蛋

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 立即注册

© 2001-2025 BBS.Monster