douwei3280 2010-12-31 07:35 采纳率: 0%
浏览 57
已采纳

PHP:Canonical Url在多语言网站上还没有傻瓜证明。 如何使其更加一致?

While setting the Canonical tag, i found out that i am not getting all the juice out of the canonical purpose...

GIVEN Currently ugly urls like website.org/juice?ln=de are made nice via apache, reachable in more userfriendly way, like website.org/de/juice. Now, in this multi-lingual website, I wish for consistency and all pages to have their languages as a folder. I wish the search engines to remember and prefer those /language/page as opposed to their ugly counterparts /page?ln=language.

Question 1: Am I sofar on the right track in how i want to use Canonical to communicate this to the search engines out there?

CURRENTLY the code removes unneccessary strings sothat canonical urls are short:
when URL = http://website.org/de/juice?ln=whatever
canocal url= http://website.org/de/juice

Sofar so good, BUT, it does not rewrite the old files roaming on the net/old search engine cache memories, and thus following situations go wrong:
when URL = http://website.org/juice?ln=xyz (missing language folder)
then canonical becomes = http://website.org/juice (whereas it should be http://website.org/xyz/juice

Question 2: what should i add to my code, do to improve/ foolproof my canonical sothat it recognises situations where there is no language folder set?

<?php
$domain = $_SERVER['HTTP_HOST'];     #domain like  website.org
$qsIndex = strpos($extensions, '?'); # strip off of string/query part (?ln=xyz)
$pageclean = $qsIndex !== FALSE ? substr($extensions, 0, $qsIndex) : $extensions;

$canonical = "http://" . $domain . $pageclean; 
?>

<html><head><link rel="canonical" href="<?=$canonical?>"></head>...

note: languages can be things like {de, nl, es, it, en, la, .... but also zh-CN, zh-TW} so whatever that comes after ln?=

  • 写回答

2条回答 默认 最新

  • doulian4467 2011-01-04 12:00
    关注

    well, does your page

    not the URL, but the page know what language it is? if yes, just add the language information in the canonical URL, if the page does not know what language it is (and you have no way to find out) you will just have to choose a default language parameter. not perfect from a SEO point of view, but much better than having these old URLs stay/stray around.

    as a parachute you can use the new <link rel="alternate" ...> tag to soften that effect.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名