简体   繁体   English

如何以不同语言显示页面?

[英]How to show a page in different languages?

I use this meta tags to make google crawler know that I have two languages for my site, as suggested here support.google . 我使用这个元标记让Google抓取工具知道我的网站有两种语言,如support.google所示

<link rel="alternate" hreflang="x-default" href="http://www.example.com" />
<link rel="alternate" hreflang="de" href="http://www.example.com/de" />
<link rel="alternate" hreflang="en" href="http://www.example.com/en" />

So sometimes the content of example.com would be the same as example.com/de and sometimes example.com would be the same as example.com/en . 所以有时的内容example.com是一样example.com/de有时example.com是一样example.com/en

I use the following code to detect language 我使用以下代码来检测语言

const lang = (
     getLangFromUrl(req.url) || 
     getLangFromCookies(req.cookies) || 
     getLangFromHeader(req.headers) || 
     'de'
);

and google detects example.com and example.com/de as duplicated pages. 谷歌检测example.comexample.com/de作为重复页面。

Can you please tell me how should it be correctly done? 你能告诉我怎么做得对吗?

Google has mentioned this issue in this link: support.google.com Google在此链接中提到了此问题: support.google.com

If you prefer to dynamically change content or reroute the user based on language settings, be aware that Google might not find and crawl all your variations. 如果您希望动态更改内容或根据语言设置重新路由用户,请注意Google可能无法找到并抓取您的所有变体。 This is because the Googlebot crawler usually originates from the USA. 这是因为Googlebot抓取工具通常来自美国。 In addition, the crawler sends HTTP requests without setting Accept-Language in the request header. 此外,爬网程序发送HTTP请求而不在请求标头中设置Accept-Language。

I hope this will help you 我希望这能帮到您

Handling duplicate pages with multilingual/multi-regional sites 处理具有多语言/多区域站点的重复页面

If you provide similar or duplicate content on different URLs in the same language as part of a multi-regional site (for instance, if both example.de/ and example.com/de/ show similar German language content), you should pick a preferred version and use the rel=canonical element and hreflang tags to make sure that the correct language or regional URL is served to searchers. 如果您在与多地区网站的一部分相同语言的不同网址上提供类似或重复的内容(例如,如果example.de/example.com/de/显示类似的德语内容),您应该选择一个首选版本并使用rel = canonical元素和hreflang标记来确保向搜索者提供正确的语言或区域URL。

You can find here the Google guide to Consolidate duplicate URLs: https://support.google.com/webmasters/answer/139066?hl=en 您可以在此处找到合并重复网址的Google指南: https//support.google.com/webmasters/answer/139066?hl = zh-CN

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM