Session 与 URI 多语言标识符

发布于 2024-11-07 14:03:53 字数 103 浏览 4 评论 0原文

我正在开发一个多语言网站 (php/mysql),我的问题是语言识别的最佳解决方案是什么 - 会话/cookie 或 URI 识别。我的意思是在SEO方面,什么会更准确。

谢谢

I am working on a multilingual website (php/mysql) and my question is what would be the best solution for language identification - sessions/cookies or URI identification. I mean in terms of SEO, what would be more accurate.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

抠脚大汉 2024-11-14 14:03:53

有不同类型的项目不应使用相同的语言实现。

让我举一些例子:

  1. 第一个项目有一个域名,比如说 example.com。该网站应提供三种语言版本。为了让搜索引擎清楚地抓取和索引每种语言 - 这里正确的解决方案是通过 url 传递它。 example.com/fr/ 代表法语。

  2. 第二个项目,每种语言都有一个域名,example.fr、example.co.uk。最好每个域仅由搜索引擎按其主要语言进行索引。因此,我选择的解决方案是在切换时将语言存储在 cookie 中。 (或完全重定向到另一个域)。

如果我们选择示例 1 的解决方案作为示例 2,则 example.co.uk/fr/ 和 example.fr 将具有相同的内容,这对 SEO 不友好。

There are different types of projects which shouldn't use the same language implementation.

Let me give some examples:

  1. The first project has an single domain name, let's say example.com. This website, should be available in three languages. In order to let the search engine clearly crawl and index each language - the correct solution here would be passing it by url. example.com/fr/ for french.

  2. The second project, has an domain name for each language, example.fr, example.co.uk. It would be best that each domain is only indexed by the search engine by it's primary language. Therefor, the solution I'd pick would be storing the language in a cookie when switching. (or redirect to the other domain entirely).

If we'd pick the solution of example 1 for example 2, both example.co.uk/fr/ and example.fr would have the same content, which isn't SEO friendly.

日裸衫吸 2024-11-14 14:03:53

网址。您可以对所有路径使用类似“/en/”的前缀。显然您会使用 mod_rewrite 或适当的框架路由配置。

URL. You can use something like a '/en/' prefix to all paths. Obviously you'd use mod_rewrite or appropriate framework routing config.

燃情 2024-11-14 14:03:53

如果您将语言放入 URI 中,网络爬虫就可以用不同的语言对站点进行索引,并且用户可以为它们添加书签/链接。如果没有对页面的直接引用(=> URL),这是不可能的。

您可以结合使用这两种方法:如果 URI 中没有可用的语言特定信息,请尝试从 cookie/会话中查找它,如果失败,请查看 Accept-Language-Header。现在,如果一个用户更改语言(通过链接或其他方式),请将其写入 cookie(以供以后访问)。

If you put the language into the URI a webcrawler can index the site in its different languages and users are able to bookmark/link to them. This is not possible, if there is no direct reference (=> URL) to the pages.

You can combine both ways: If no language specific information available within the URI, try to find it out from a cookie/session, and if this one fails, look at the Accept-Language-Header. Now, if one user change the language (by link or whatever) write it into a cookie (for later visits).

满意归宿 2024-11-14 14:03:53

仅使用会话/cookie,某人实际上不可能直接链接到您内容的“斯瓦希里语”版本。相反,您将拥有所有传入链接都指向的默认语言(英语?)。一旦到达那里,如果用户想要你的普通话内容,那么他​​们可以选择该选项,但他们不会直接得到它,所以使用 URI 识别是我个人的选择。

有几种方法可以标记 URI 中使用的语言,可以通过设置某种目录结构,例如:http://domain.tld/localized/fr/法语内容的主页,或者您可以在数据库中将其抽象出来并通过 GET 变量识别语言:http://domain.tld/?l=4对于 ID 为 4 的语言的主页

或者,正如 Wesley van Opdorp 指出的那样,您可以为每种语言设置单独的域或子域:http://domain.fr 或 < code>http://fr.domain.tld

就 SEO 而言,我相信最好的方法是遵守顶级域名标准,并为您想要托管的每种语言设置一个单独的域站点(http://domain.frhttp://domain.ru 等)。这当然意味着购买更多域名,所以如果这不是一个选择,我的第二选择是为每种语言设置子域名,例如:http://fr.domain.tldhttp://ru.domain.tld

Using only sessions/cookies, it wouldn't really be possible for someone to link straight to the 'Swahili' version of your content. Instead, you would have a default language (English?) which all incoming links would point to. Once there, if a user wanted your content in Mandarin then they could choose that option, but they won't get it straight out of the gate so using URI identification is my personal pick.

There are a couple of ways to tag what language to use in the URI, either by setting up some sort of directory structure, such as: http://domain.tld/localized/fr/ for the main page of the french content, or you can abstract it out in your database and identify the language through GET variables: http://domain.tld/?l=4 for the main page of language with ID of 4

Or, as Wesley van Opdorp pointed out, you can set up a separate domain or sub-domain for each language: http://domain.fr or http://fr.domain.tld

As far as SEO goes, I believe the best way would be to adhere to the Top Level Domain Standards and set up a separate domain for each language you want to host the site in (http://domain.fr, http://domain.ru, etc). This of course would mean purchasing more domains, so if that isn't an option my second choice would be to set up sub-domains for each langauge such as in: http://fr.domain.tld and http://ru.domain.tld

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文