开发多语言网站的任何想法 - SEO、php、mysql

发布于 2024-10-21 22:18:31 字数 1540 浏览 1 评论 0原文

我刚刚完成了客户的网站,现在他们想要不同的语言。

目前,网站内容存储在 MySQL 数据库的表中:

  • 页面seotitleseodescsmallHtml< /em>、fullHtml

  • 产品IDseotitleseodesc、< em>smallHtml、fullHtml

我在想一个好方法是有一个额外的表:

  • 语言:< em>ID、LanguageCode语言

然后将页面和产品表修改为:

  • 页面slug seotitleseodescsmallHtmlfullHtml语言代码
  • 产品IDslugseotitle、seodescsmallHtmlfullHtmllanguageCode

所以我会使用 这样的查询吗

SELECT * FROM pages WHERE slug = '$slug' AND language='$language'

像“我应该将 $language 设置为 cookie 还是会话?”

?另外,就 SEO 而言,我一直困惑于该做什么。目前站点 URL 结构为 /pages.php?slug=page-slug。 mod_rewrite 将其重写为 /pages/page-slug

所以我正在考虑将 /pages.php?slug=page-slug&code=languagecode 重写为 /pages/page-slug/languagecode 。产品也一样。

这是一个好方法还是你会看到它以某种方式失败?

如果有人有更好的方法或我可能错过的资源链接,将不胜感激。

感谢您的阅读。

编辑/////

如果我要使用此方法 http://en.kioskea.net/faq/596-change-the-language-of-your-website 并更改幕后语言,而不更改网址结构 Google 将如何处理此问题?

I have just finished a client’s website and now they want to have different languages.

At the moment the sites content is stored on tables in a MySQL db:

  • pages: seotitle, seodesc, smallHtml, fullHtml

  • products: ID, seotitle, seodesc, smallHtml, fullHtml

I was thinking a good way to do it would be to have an extra table:

  • languages: ID, LanguageCode, language

Then modify the pages and products table to:

  • pages: slug, seotitle, seodesc, smallHtml, fullHtml, languageCode
  • products: ID, slug, seotitle, seodesc, smallHtml, fullHtml, languageCode

So I would be using a query like

SELECT * FROM pages WHERE slug = '$slug' AND language='$language'

Should I set $language as a cookie or session?

Also, I am stuck on what to do as far as SEO goes. At the moment the site URL structure is /pages.php?slug=page-slug. This gets rewritten by mod_rewrite to /pages/page-slug.

So I was thinking of having /pages.php?slug=page-slug&code=languagecode rewriting to /pages/page-slug/languagecode. Same for products.

Would this be a good method or can you see it failing somehow?

If anyone has any better methods or links to resources I may have missed that would be much appreciated.

Thanks for reading.

EDIT/////

If I was to use this method http://en.kioskea.net/faq/596-change-the-language-of-your-website and change the language behind the scenes, without changing the URL structure how would Google handle this?

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

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

发布评论

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

评论(2

仲春光 2024-10-28 22:18:31

Google 和其他搜索引擎不会尝试通过检查网址来猜测语言,重要的是内容

Google 使用页面内容来确定其语言,但 URL 本身为人类用户提供有关页面内容的有用线索。

这就是为什么您应该正确声明内容的语言:在 HTTP 中使用 < a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.12" rel="nofollow noreferrer">内容语言指定文档的默认语言并使用 lang文档中更改的语言属性。

拥有多语言网站时,您还应该考虑进行某种语言协商(另请参阅我对检测 PHP 中的浏览器语言);但也要考虑与之相关的细微差别(请参阅常见 HTTP 实现问题)。

然而,选择合适的 URI 结构也很重要——即使只是对于用户而言。这意味着 URI 应反映所选语言(除非您想为语言协商提供独立于语言的入口点)。

但是您选择什么 URI 设计取决于您。从用户的角度去做。

Google and other search engines don’t try to guess the language by inspecting the URL, it’s the content that matters:

Google uses the content of the page to determine its language, but the URL itself provides human users with useful clues about the page’s content.

This is why you should declare the content’s language properly: In HTTP use Content-Language to specify the document’s default language and use the lang attribute for language changed within the document.

Having a multilingual web site you should also consider doing some kind language negotiation (see also my answer to Detect Browser Language in PHP); but also take the nuances into account that are associated with it (see Common HTTP Implementation Problems).

But yet, choosing an appropriate URI structure is also important – even if only for the users. That means the URI should reflect the chosen language (unless you want to provide a language-independent entry point for language negotiation).

But what URI design you choose is up to you. Do it from the user’s perspective.

凑诗 2024-10-28 22:18:31

基础知识,每个表都应该有一个 ID,如果您按照建议更改它,看起来 Pages 会丢失它。

许多主要网站(包括维基百科)都使用语言的 2 位 ISO 缩写将语言作为子域前缀,例如 English = en 等。这将使您的 URL 看起来类似于 en.websitename.com 。请记住,大多数多语言网站的 URL 中都没有显示默认语言,因此,如果您的默认语言为英语,则英语将为 www.websitename.com,但法语将为 < em>fr.websitename.com。这似乎是一种普遍接受的方法,并且还有助于在查看子页面时使 URL 看起来更干净。除了语言位之外,您的其他页面 URL 结构看起来对 SEO 友好。

您需要考虑访问者首先如何进入您的域,是进入您的主主页还是子页面(主要通过搜索引擎)。然后,您应该尝试将用户从网络浏览器重定向到该语言(请参阅此处 一个好方法来做到这一点)。尽管如果用户(第一次访问)要访问的内容与浏览器的语言不同也是一个好主意,那么提供一种访问这两个版本的清晰方法对可用性很有好处,然后您可以通过cookie/会话。

其他 SEO 技巧:请参阅 这里了解基础知识。

Basics, each table should have an ID, looks like Pages would be missing it if you changed it as proposed.

Many major websites (including Wikipedia) have the language prefixed as a subdomain using the 2 digit ISO abbreviation for languages, e.g. English = en, etc. Which would make your URLs look similar to en.websitename.com. Bear in mind though that most multi-language websites don't have the default language shown in the URL, so if English is your default then English would be www.websitename.com but the French would be fr.websitename.com. This seems to be a commonly accepted approach, and also helps the URLs look cleaner when viewing subpages. Your other page URL structure looks SEO friendly apart from the language bit.

You'll need to think about how a visitor is first going to enter your domain, whether to your main homepage or to a subpage (via search engines mostly). With that you should then try and redirect the user to the language from there web browser (see here for a good way to do this). Although it's also a good idea if the content the user (on there first visit) was going to is different to the language of there browser then it's good for usability to offer a clear way to access both versions, which you would then remember via a cookie/session.

Other SEO tips: see here for the basics.

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