根据浏览器语言重定向用户(不是在php中) [英] Redirect users based on browser language (not in php)

查看:126
本文介绍了根据浏览器语言重定向用户(不是在php中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站将使用3种语言。法语(fr)是默认语言。
该网站的结构如下:

根目录(注意:我没有使用php文件,只是纯html)

  / fr / 
Index.html
About-us.html
Contact.html

/ en /
Index.html
About-us.html
Contact.html
$ b $ / de /
Index.html
About-us.html
Contact.html

我有疑问:




  • 根据网页浏览器语言重定向用户的最佳做法是什么?通过htaccess?

  • 我是否需要在根目录下有一个index.html页面(对于SEO原因或其他原因)?法国的index.html或许?


解决方案

超级简单的工具在这里:



http://www.htaccesstools.com/redirection- by-language /



使基于浏览器语言的htaccess重定向变得非常简单。



例子:
$ b $ pre $ $ $ c $ RewriteEngine on
RewriteCond%{HTTP:Accept-Language}(fr)[NC]
RewriteRule。* /fr/index.html [L]
RewriteCond%{HTTP:Accept-Language}(en)[NC]
RewriteRule。* /en/index.html [L]
RewriteCond%{HTTP:Accept-Language}(de)[NC]
RewriteRule。* /de/index.html [L]

这是一个硬重定向,浏览器的位置栏确实会显示新的页面。尽管如此,这对UX来说比内部重定向掩盖了URL更好。



为了回答你的问题,高度认为index.html提供了最好的用户体验。但是,这基本上是因为人们普遍期待这一点(网站:http://www/,website.com/fr/等)。 SEO明智的,不,如果你没有遵循同样的结构,你就不会受到伤害。



最好的做法是用你最好的猜测(比如htaccess) ,并仍然提供切换语言的菜单。另外,如果Accept-Language没有实际定义(比如默认进入/ en /),还需要回退。这可能是htaccess中的最后一行,或者它可以简单地在根级别是 index.html ,其中 .htaccess

除此之外,没有大量数据进入本地化。


My website will be in 3 languages. French (fr) is the default language. The structure of the site is the following:

Root directory (note: I'm not using php files, just plain html)

/fr/
    Index.html
    About-us.html
    Contact.html

/en/
    Index.html
    About-us.html
    Contact.html

/de/
    Index.html
    About-us.html
    Contact.html

I got questions:

  • What is the best practice to redirect users based on their web browser language? Via htaccess?
  • Do I need a index.html page at root level (for SEO reason or any other reason) ? The French index.html perhaps?

解决方案

Super easy tool here:

http://www.htaccesstools.com/redirection-by-language/

Makes life incredibly easy for htaccess redirects based on the browser's language.

Example:

RewriteEngine on
RewriteCond %{HTTP:Accept-Language} (fr) [NC]
RewriteRule .* /fr/index.html [L]
RewriteCond %{HTTP:Accept-Language} (en) [NC]
RewriteRule .* /en/index.html [L]
RewriteCond %{HTTP:Accept-Language} (de) [NC]
RewriteRule .* /de/index.html [L]

This is a hard redirect, the browser's location bar will indeed show the new page. Though, this is better for UX than an internal redirect masking the URL.

To answer your question, it is highly regarded that an index.html provides the best UX. However, that's essentially because people have come to expect this in general (website.com/en/, website.com/fr/, etc.). SEO-wise, no, you wouldn't get dinged if you didn't follow that same structure.

Best practice is to use your best guess (like the htaccess), and still offer a menu for switching languages. Plus, you'll also need a fallback for if the Accept-Language isn't actually defined (like going to /en/ by default). This could be a final line in the htaccess, or it could simply be an index.html at the root level, where .htaccess is.

Other than that, there's not a tremendous amount that goes into localization.

这篇关于根据浏览器语言重定向用户(不是在php中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆