我应该为多语言站点设置哪个 http headers?

Which http headers should I set for multi language site?

我目前正在一个多语言网站上工作,这是我的情况:

根据this and this 文章中的回答,我也需要设置一个http-header,但我不知道该怎么做以及我应该设置什么样的header .是 Accept-Language 还是 Content-Language? multi-language 网站真的必须设置 http-header 吗? Accept-Language 是请求而不是响应吗?

请帮忙!谢谢!

And is it really a must to set a http-header for multi-language websites?

来自 HTTP headers, meta elements and language information - W3.org:

When specifying the language for text-processing you are declaring the language in which a specific range of text is actually written, so that user agents or applications that manipulate the text (such as voice browsers, spell checkers, or style processors) can effectively handle the text in question.

所以是的,从可用性的角度来看,声明页面上使用的语言以及页面目标受众的语言是有意义的。

有关如何指定,请参阅同一页面:

The HTTP Content-Language header can be used to provide metadata about the intended audience of the page, and can indicate that this is more than one language. The Content-Language value for an http-equiv attribute on a meta element should no longer be used. You should use a language attribute on the html tag to declare the default language of the actual text in the page.

HTML meta tag for content language

should really be expressed in the headers. For example:

Content-language: es

Accept-Language 不是响应 header 而是请求 header,因此 Content-language 作为响应 header 和 <html lang=""> 属性中的 HTML 元素你很高兴。

至于Vary: X, Y响应header:这意味着对当前请求URI的响应将在header时有所不同 X或 Y 不同。

这在进行重定向时很重要。假设在您的着陆页上,您根据 Accept-Language 请求 header:

确定重定向到哪里
GET / HTTP/1.1
Host: example.com
Accept-Language: en

您的站点随后将重定向到英文子站点:

HTTP/1.1 302 Found
Location: http://example.com/en
Vary: Accept-Language

这将告诉用户代理(浏览器、搜索引擎)使用不同的 Accept-Language 请求相同的 URI 将产生不同的结果。例如:

GET / HTTP/1.1
Host: example.com
Accept-Language: es

您的站点随后将重定向到西班牙语子站点:

HTTP/1.1 302 Found
Location: http://example.com/es
Vary: Accept-Language