15
Jun

升级到WordPress 2.2后permalink的反斜杠问题

把博客升级到WordPress 2.2,挂上google adsense广告后,点击几个归档页面发现全是公益广告,查了一下原因,原来page页、archive页、category页url中的反斜杠不见了。没有反斜杆的页面和带反斜杆的页面,google adsense蜘蛛认为是两个页面,没有反斜杠的页面被认为是新页面,自然没有广告匹配了。

原来的地址 http://sheawey.com/blog/2007/06/
被改变的地址 http://sheawey.com/blog/2007/06

这对于seo来说,是个很严重的问题,容易造成复制网页,并且可能进入“补充材料”。你可以从下面一个博客的搜索截图可以了解到:

不是补充材料

是补充材料

因为以前在搜索引擎里面被收录的时候是带反斜杠的,如果现在不带反斜杠,形成“补充材料”倒是次要的,我担心我的博客会被google惩罚,类似于“黑色梦中的SEO博客”一样

一般在WordPress 2.2后台开启permalink是不会出现我的这种情况的,如点石互动就没有。我出现这个问题主要是因为我把permalink设置为/%postname%.html,而一般的人都会设置为/%year%/%monthnum%/%day%/%postname%/,后者是没有任何问题的,前者在WordPress 2.2就出现了反斜杠的问题了。

怎么去解决这个反斜杆呢?

你可以在.htaccess文件中写重写url规则,我是直接修改了几个文件,如下:

wp-includes/link-template.php

193行,找到get_month_link函数,这个函数是关于月份归档的,修改

return apply_filters(’month_link’, get_option(’home’) . user_trailingslashit($monthlink, ‘month’), $year, $month);



return apply_filters(’month_link’, get_option(’home’) . user_trailingslashit($monthlink, ‘month’), $year, $month).’/';

wp-includes/link-template.php

117行,找到get_page_link函数,这个是有关Page的,修改

return apply_filters(’page_link’, $link, $id);



return apply_filters(’page_link’, $link, $id).”/”;

wp-includes/category-template.php

23行,找到get_category_link函数,这个是关于category分类的,修改:

return apply_filters(’category_link’, $catlink, $category_id);



return apply_filters(’category_link’, $catlink, $category_id).’/';

6 Comments

Leave a comment

Name(required)
Mail (will not be published)(required)
Website

Fields in bold are required. Email addresses are never published or distributed.

Some HTML code is allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
URIs must be fully qualified (eg: http://www.dupola.com) and all tags must be properly closed.

Line breaks and paragraphs are automatically converted.

Please keep comments relevant. Off-topic, offensive or inappropriate comments may be edited or removed.

    About

      这是sheawey的blog。原创内容谢绝所有商业媒体转摘。更多介绍请看这里

    Tag Cloud