当前位置

多语言网站之间用rel="alternate" hreflang="x"链接起来

James Qi 在 2013年8月15日 - 16:06 提交
内容摘要:我们用Drupal做过桌面版网站、手机版网站,中文版网站、英文版网站、更多语言版本网站,这些站之间除了页面看得见的互相链接以外,还可以而且应该在源代码中进行链接,以便让搜索引擎更了解页面之间的关系。 ......

  我们用Drupal做过桌面版网站、手机版网站,中文版网站、英文版网站、更多语言版本网站,这些站之间除了页面看得见的互相链接以外,还可以而且应该在源代码中进行链接,以便让搜索引擎更了解页面之间的关系。

  请看Google的推荐:

  手机版链接我们以前添加过,现在也来添加多语言版本,Drupal 7中可以修改html.tpl.php来实现,Drupal 6可以通过修改page.tpl.php来实现。

  Drupal 7的代码例子如下:

<?php

$server_name=$_SERVER['SERVER_NAME'];
$request_uri=$_SERVER['REQUEST_URI'];

$array_lang=array("af","sq","ar","hy","az","bg","ca","zh-hans","zh-hant","hr","cs","da","nl","eo","et","fi","fil","fr","gl","ka","de","el","hu","is","ga","it","ja","ko","lv","lt","mk","ms","mt","fa","pl","pt","ro","ru","sr","sk","sl","es","sw","sv","th","tr","uk","vi","cy");
global $base_url;
$url="http://$server_name$request_uri";
$url_path=str_replace("$base_url/",'',$url);
$lang_code=strtok($url_path,'/');
if (in_array($lang_code,$array_lang)) {
  $url_default=$base_url.substr($url_path,strlen($lang_code));
} else {
  $lang_code='en';
  $url_default=$url;
}
//print "  <link rel=\"alternate\" hreflang=\"x-default\" href=\"$url_default\" />\n";
print "  <link rel=\"alternate\" hreflang=\"en\" href=\"$url_default\" />\n";

foreach ($array_lang as $lang_code1) {
  $url_lang=str_replace($base_url,"$base_url/$lang_code1",$url_default);
  print "  <link rel=\"alternate\" hreflang=\"$lang_code1\" href=\"$url_lang\" />\n";
}

?>

  多语言的手机版和多语言的电脑版中都可以在<head></head>之间加入以上部分。

  查看网页源代码,效果类似如下:

<link rel="alternate" media="handheld" href="http://m.industry.bizdirlib.com/sic01/uk/node/2"/>
  <link rel="canonical" href="http://industry.bizdirlib.com/sic01/uk/node/2" />
  <link rel="alternate" hreflang="x-default" href="http://m.industry.bizdirlib.com/sic01/node/2" />
  <link rel="alternate" hreflang="en" href="http://m.industry.bizdirlib.com/sic01/node/2" />
  <link rel="alternate" hreflang="af" href="http://m.industry.bizdirlib.com/sic01/af/node/2" />
  <link rel="alternate" hreflang="sq" href="http://m.industry.bizdirlib.com/sic01/sq/node/2" />
  <link rel="alternate" hreflang="ar" href="http://m.industry.bizdirlib.com/sic01/ar/node/2" />
  <link rel="alternate" hreflang="hy" href="http://m.industry.bizdirlib.com/sic01/hy/node/2" />
  <link rel="alternate" hreflang="az" href="http://m.industry.bizdirlib.com/sic01/az/node/2" />
  <link rel="alternate" hreflang="bg" href="http://m.industry.bizdirlib.com/sic01/bg/node/2" />
  <link rel="alternate" hreflang="ca" href="http://m.industry.bizdirlib.com/sic01/ca/node/2" />
  <link rel="alternate" hreflang="zh-hans" href="http://m.industry.bizdirlib.com/sic01/zh-hans/node/2" />
  <link rel="alternate" hreflang="zh-hant" href="http://m.industry.bizdirlib.com/sic01/zh-hant/node/2" />
  <link rel="alternate" hreflang="hr" href="http://m.industry.bizdirlib.com/sic01/hr/node/2" />
  <link rel="alternate" hreflang="cs" href="http://m.industry.bizdirlib.com/sic01/cs/node/2" />
  <link rel="alternate" hreflang="da" href="http://m.industry.bizdirlib.com/sic01/da/node/2" />
  <link rel="alternate" hreflang="nl" href="http://m.industry.bizdirlib.com/sic01/nl/node/2" />
  <link rel="alternate" hreflang="eo" href="http://m.industry.bizdirlib.com/sic01/eo/node/2" />
  <link rel="alternate" hreflang="et" href="http://m.industry.bizdirlib.com/sic01/et/node/2" />
  <link rel="alternate" hreflang="fi" href="http://m.industry.bizdirlib.com/sic01/fi/node/2" />
  <link rel="alternate" hreflang="fil" href="http://m.industry.bizdirlib.com/sic01/fil/node/2" />
  <link rel="alternate" hreflang="fr" href="http://m.industry.bizdirlib.com/sic01/fr/node/2" />
  <link rel="alternate" hreflang="gl" href="http://m.industry.bizdirlib.com/sic01/gl/node/2" />
  <link rel="alternate" hreflang="ka" href="http://m.industry.bizdirlib.com/sic01/ka/node/2" />
  <link rel="alternate" hreflang="de" href="http://m.industry.bizdirlib.com/sic01/de/node/2" />
  <link rel="alternate" hreflang="el" href="http://m.industry.bizdirlib.com/sic01/el/node/2" />
  <link rel="alternate" hreflang="hu" href="http://m.industry.bizdirlib.com/sic01/hu/node/2" />
  <link rel="alternate" hreflang="is" href="http://m.industry.bizdirlib.com/sic01/is/node/2" />
  <link rel="alternate" hreflang="ga" href="http://m.industry.bizdirlib.com/sic01/ga/node/2" />
  <link rel="alternate" hreflang="it" href="http://m.industry.bizdirlib.com/sic01/it/node/2" />
  <link rel="alternate" hreflang="ja" href="http://m.industry.bizdirlib.com/sic01/ja/node/2" />
  <link rel="alternate" hreflang="ko" href="http://m.industry.bizdirlib.com/sic01/ko/node/2" />
  <link rel="alternate" hreflang="lv" href="http://m.industry.bizdirlib.com/sic01/lv/node/2" />
  <link rel="alternate" hreflang="lt" href="http://m.industry.bizdirlib.com/sic01/lt/node/2" />
  <link rel="alternate" hreflang="mk" href="http://m.industry.bizdirlib.com/sic01/mk/node/2" />
  <link rel="alternate" hreflang="ms" href="http://m.industry.bizdirlib.com/sic01/ms/node/2" />
  <link rel="alternate" hreflang="mt" href="http://m.industry.bizdirlib.com/sic01/mt/node/2" />
  <link rel="alternate" hreflang="fa" href="http://m.industry.bizdirlib.com/sic01/fa/node/2" />
  <link rel="alternate" hreflang="pl" href="http://m.industry.bizdirlib.com/sic01/pl/node/2" />
  <link rel="alternate" hreflang="pt" href="http://m.industry.bizdirlib.com/sic01/pt/node/2" />
  <link rel="alternate" hreflang="ro" href="http://m.industry.bizdirlib.com/sic01/ro/node/2" />
  <link rel="alternate" hreflang="ru" href="http://m.industry.bizdirlib.com/sic01/ru/node/2" />
  <link rel="alternate" hreflang="sr" href="http://m.industry.bizdirlib.com/sic01/sr/node/2" />
  <link rel="alternate" hreflang="sk" href="http://m.industry.bizdirlib.com/sic01/sk/node/2" />
  <link rel="alternate" hreflang="sl" href="http://m.industry.bizdirlib.com/sic01/sl/node/2" />
  <link rel="alternate" hreflang="es" href="http://m.industry.bizdirlib.com/sic01/es/node/2" />
  <link rel="alternate" hreflang="sw" href="http://m.industry.bizdirlib.com/sic01/sw/node/2" />
  <link rel="alternate" hreflang="sv" href="http://m.industry.bizdirlib.com/sic01/sv/node/2" />
  <link rel="alternate" hreflang="th" href="http://m.industry.bizdirlib.com/sic01/th/node/2" />
  <link rel="alternate" hreflang="tr" href="http://m.industry.bizdirlib.com/sic01/tr/node/2" />
  <link rel="alternate" hreflang="uk" href="http://m.industry.bizdirlib.com/sic01/uk/node/2" />
  <link rel="alternate" hreflang="vi" href="http://m.industry.bizdirlib.com/sic01/vi/node/2" />
  <link rel="alternate" hreflang="cy" href="http://m.industry.bizdirlib.com/sic01/cy/node/2" />

 

评论

-- 发自IP地址: 61.183.172.45 (位置 | 谁是)

最近收到Google Webmaster Tools的提醒邮件,接到下面Incorrect rel-alternate-hreflang implementation这样的通知:

Dear webmaster of http://sic08.bizdirlib.com/,

We have noticed that on a number of the pages on your site the rel-alternate-hreflang implementation is incorrect. For example:

http://sic08.bizdirlib.com/m/node/10088

In particular, there seems to be a problem with missing or incorrect bi-directional linking (when page A links with hreflang to page B, there must be a link back from B to A as well). When our algorithms detect conflicting signals like on these pages, they may make indexing and ranking decisions that do not match what you intended.

To learn more about rel-alternate-hreflang, see the following Help Center article: https://support.google.com/webmasters/answer/189077

If you have any questions about how to resolve this issue, please visit our Help Forum:

http://productforums.google.com/forum/#!categories/webmasters/internationalization

Sincerely,
The Google Search Quality Team
详细查看相关资料后,觉得是x-default的用法可能有误,这个用于多语言的选择页面,我们可以在模板中去掉这行。

James Qi / 祁劲松

-- 发自IP地址: 58.49.165.5 (位置 | 谁是)

您好!我上面这篇写的是多语言网站加对应页面的链接,您的日文网站如果是纯日文的就没法添加也无需添加了,如果页面有对应的中文或者英文等版本网站的页面才需要添加这种链接。

举例,如果您的日文网站页面http://ja.example.com/page.html有对应的中文页面http://zh.example.com/page.html,就在这个日文网站的源代码中添加一行:

<link rel="alternate" hreflang="zh" href="http://zh.example.com/page.html" />

反过来在中文页面中添加一行指向日文网站对应页面的链接:

<link rel="alternate" hreflang="ja" href="http://ja.example.com/page.html" />

James Qi / 祁劲松

添加新评论

Plain text

  • 不允许使用HTML标签。
  • 自动将网址与电子邮件地址转变为链接。
  • 自动断行和分段。
验证码
本问题用于测试您是否为人类访问者,避免自动垃圾发贴。
图形验证
键入显示在图片中的字符