我们用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" />
评论4
x-default的用法可能有误
最近收到Google Webmaster Tools的提醒邮件,接到下面Incorrect rel-alternate-hreflang implementation这样的通知:
详细查看相关资料后,觉得是x-default的用法可能有误,这个用于多语言的选择页面,我们可以在模板中去掉这行。
シャネルコピー
我想问一下我的是日文站加那一个。多语言网站加对应页面的链接
您好!我上面这篇写的是多语言网站加对应页面的链接,您的日文网站如果是纯日文的就没法添加也无需添加了,如果页面有对应的中文或者英文等版本网站的页面才需要添加这种链接。
举例,如果您的日文网站页面http://ja.example.com/page.html有对应的中文页面http://zh.example.com/page.html,就在这个日文网站的源代码中添加一行:
反过来在中文页面中添加一行指向日文网站对应页面的链接:
想咨询一下做了一个英文站点,想要再做一个日语,法语,韩语,阿拉伯语之类的语音都做成不同的页面怎么改?
想咨询一下做了一个英文站点,想要再做一个日语,法语,韩语,阿拉伯语之类的语音都做成不同的页面怎么改?求教大神