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条)

报告相同问题?

悬赏问题

  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因