百
度最近宣布支持Canonical标签,Canonical就是让我们可以为页面定义一个标准的URL,我们一个网页,特别动态页面,因为传入参数顺序的
不同,所以会造成同样的内容多个版本的URL,这样容易被百度认为是重复内容,甚至有被惩罚的风险。
Canonical标签的出现很好的解决了这个问题,谷歌等其它国外的搜索引擎很早就支持了Canonical。 但是DedeCMS要想动态输出一
个标准的URL,也还是需要做一些工作
Canonical的写法:
1
|
< link rel = "canonical" href = "http://www.0937.biz/" />
|
|
织梦DedeCMS首页模板的写法:
1
|
< link rel = "canonical" href = "{dede:global.cfg_basehost/}" />
|
|
织梦DedeCMS频道页模板的写法:
1
|
< link rel = "canonical" href = "{dede:field.typeurl/}" />
|
织梦DedeCMS列表页模板的写法:
|
1
|
< link rel = "canonical" href = "{dede:field.typeurl/}" />
|
织梦DedeCMS内容页模板的写法:
|
1
|
< link rel = "canonical" href = "{dede:field.arcurl/}" />
|
但是我们会发现,当内容分页的时候,分页的URL不正确,解决办法,打开/include/arc.archives.class.php
搜索”$TRUEfilename =
$this->GetTruePath().$fileFirst."_".$i.".".$this->ShortName;“
在下面添加一段代码:
|
1
|
$TRUEfilename = $this ->GetTruePath(). $fileFirst . "_" . $i . "." . $this ->ShortName;
|
2
|
GLOBAL $cfg_multi_site ;
|
3
|
if ( $cfg_multi_site == ’Y’ ) {
|
4
|
$this ->Fields[ ’arcurl’ ] = $cfg_basehost . $fileFirst . "_" . $i . "." . $this ->ShortName;
|
6
|
$this ->Fields[ ’arcurl’ ] = $fileFirst . "_" . $i . "." . $this ->ShortName;
|
|
频道页的也需要修改代码,打开/include/arc.listview.class.php 搜索”$this->PartView->SetTemplet($tempfile);“,在其上面添加一段代码:
01
|
if (! file_exists ( $tempfile ))
|
03
|
$tempfile = $tmpdir . "/" . $GLOBALS [ ’cfg_df_style’ ]. "/index_default.htm" ;
|
05
|
GLOBAL $cfg_multi_site , $cfg_basehost ;
|
06
|
if ( $cfg_multi_site == ’Y’ ) {
|
07
|
$this ->PartView->Fields[ ’typeurl’ ] = $cfg_basehost .MfTypedir( $this ->Fields[ ’typedir’ ]);
|
09
|
$this ->PartView->Fields[ ’typeurl’ ] = MfTypedir( $this ->Fields[ ’typedir’ ]);
|
11
|
$this ->PartView->SetTemplet( $tempfile );
|
|
列表页的修改有些麻烦,也会影响到性能,同样是/include/arc.listview.class.php,搜索“$this->dtp->SaveTo($makeFile);”,在他前面加上一段代码:
01
|
if ( $this ->PageNo == 1) {
|
02
|
$this ->Fields[ ’typeurl’ ] = MfTypedir( $this ->Fields[ ’typedir’ ]);
|
04
|
$this ->Fields[ ’typeurl’ ] = $murl ;
|
06
|
GLOBAL $cfg_multi_site , $cfg_basehost ;
|
07
|
if ( $cfg_multi_site == ’Y’ ) {
|
08
|
$this ->Fields[ ’typeurl’ ] = $cfg_basehost . $this ->Fields[ ’typeurl’ ];
|
11
|
$this ->ParseTempletsFirst();
|
12
|
$this ->dtp->SaveTo( $makeFile );
|
|
在修改列表这里的时候,我也发现织梦DedeCMS的一些问题,它列表的首页会有两份,一份是index.html,一份是list_num_1.html,并且内容是完全一样的,这对SEO肯定不好,定义Canonical标签应该能解决这个问题。
对于伪静态页面,则不能使用以上规则,而要使用下面这个
<link rel="canonical" href="{dede:global.cfg_basehost/}{dede:geturl runphp=’yes’}@me = GetCurUrl();{/dede:geturl}"/>
如果存在伪静态与静态页并存的现象,而我们需要将静态页以及伪静态页均显示为静态页的,那么就应该使用以下代码
<link rel="canonical" href="{dede:global.cfg_basehost/}{dede:field.id runphp=’yes’}$id=@me;@me=’’;$url=GetOneArchive($id);@me=$url[’arcurl’];{/dede:field.id}"/>
列表页以及频道页面加如下代码(但是第二页还是显示首页的网址,这个目前还没有解决,期待你的解决):
<link rel="canonical" href="{dede:global.cfg_basehost/}{dede:type typeid=’0’ row=1}[field:typelink /]{/dede:type}"/>
本文链接:https://www.0937.biz/post-99.html