用于语言重定向的HTTP状态代码 [英] HTTP Status code for language redirect

查看:120
本文介绍了用于语言重定向的HTTP状态代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我应该用语言重定向发送哪个HTTP状态代码。

I wonder which HTTP Status code I should have to send in language redirects.

我有以下php代码通过HTTP标头重定向到Accept中最重要的语言-Language浏览器标题。

I have the following php code to redirect via HTTP headers to most important language in Accept-Language browser header.

<?
$langs = array();

if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
    // break up string into pieces (languages and q factors)
    preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse);

    if (count($lang_parse[1])) {
        // create a list like "en" => 0.8
        $langs = array_combine($lang_parse[1], $lang_parse[4]);

        // set default to 1 for any without q factor
        foreach ($langs as $lang => $val) {
            if ($val === '') $langs[$lang] = 1;
        }

        // sort list based on value 
        arsort($langs, SORT_NUMERIC);
    }
}

// look through sorted list and use first one that matches our languages
foreach ($langs as $lang => $val) {
    if (strpos($lang, 'ca')===0) {
    header("location: ca/");
    exit;
    } else if (strpos($lang, 'es')===0) {
    header("location: es/");
    exit;
    } 
  echo "$lang => $val<br>";
}
// show default site or prompt for language
header("location: en/");

?>

相关问题:功能重定向的HTTP状态

也许300,301,302,303?为什么?

Maybe 300, 301, 302, 303? Why?

编辑

谷歌最近发布了这个:
< a href =http://googlewebmastercentral.blogspot.com/2011/12/new-markup-for-multilingual-content.html =nofollow noreferrer> http://googlewebmastercentral.blogspot.com/2011/12 /new-markup-for-multilingual-content.html

Google recently published this: http://googlewebmastercentral.blogspot.com/2011/12/new-markup-for-multilingual-content.html

我发现了这个:


HTTP状态300多项选择

HTTP STATUS 300 Multiple Choices

所请求的资源对应于一组
表示中的任何一个,每个表示都有自己的特定位置正在提供agent-
驱动的协商信息(第12节),以便
用户(或用户代理)可以选择首选表示,
将其请求重定向到该位置。

The requested resource corresponds to any one of a set of representations, each with its own specific location, and agent- driven negotiation information (section 12) is being provided so that the user (or user agent) can select a preferred representation and redirect its request to that location.

除非是HEAD请求,否则响应应该包含一个实体
,其中包含用户或者
的资源特征和位置列表用户代理可以选择一个mo适当的。
实体格式由Content-
类型标题字段中给出的媒体类型指定。根据

Unless it was a HEAD request, the response SHOULD include an entity containing a list of resource characteristics and location(s) from which the user or user agent can choose the one most appropriate. The entity format is specified by the media type given in the Content- Type header field. Depending upon the format and the capabilities of

用户代理的格式和功能,选择最合适的选择可以是
自动执行。但是,这个规范没有为这种自动选择定义
的任何标准。

the user agent, selection of the most appropriate choice MAY be performed automatically. However, this specification does not define any standard for such automatic selection.

如果服务器有一个首选的表示选择,它应该包括
包括Location
字段中该表示的特定URI;用户代理可以使用Location字段值进行自动
重定向。除非另有说明,否则此回复是可缓存的。

If the server has a preferred choice of representation, it SHOULD include the specific URI for that representation in the Location field; user agents MAY use the Location field value for automatic redirection. This response is cacheable unless indicated otherwise.

并且:


HTTP错误300 - 多个选择

HTTP Error 300 - Multiple choices

简介

您的Web服务器认为该URL由客户提供(例如您的
Web浏览器或我们的CheckUpDown机器人)不够具体,并且需要从多个选项进行
进一步选择。

Your Web server thinks that the URL provided by the client (e.g. your Web browser or our CheckUpDown robot) is not specific enough, and a further selection needs to be made from a number of choices.

这通常是URL表示需要进行较低级别选择的高级
分组的情况,例如
目录,用户必须在该目录中选择特定文件到
access。

This is typically the case where the URL represents a high level grouping of which lower level selections need to be made e.g. a directory within which the user must select a particular file to access.

HTTP循环中的300个错误

300 errors in the HTTP cycle

任何客户端(例如您的Web浏览器或我们的CheckUpDown机器人)在与Web服务器通信时,通过以下周期进入

Any client (e.g. your Web browser or our CheckUpDown robot) goes through the following cycle when it communicates with the Web server:

从站点的IP名称获取IP地址(站点URL
,不带前导'http://')。此查找(将IP名称转换为
IP地址)由域名服务器(DNS)提供。打开与该IP地址的IP
套接字连接。通过该套接字写入HTTP数据流
。从Web
服务器接收HTTP数据流作为响应。此数据流包含状态代码,其
值由HTTP协议确定。为
状态代码和其他有用信息解析此数据流。当客户端收到HTTP $状态代码并且
识别为'300'时,
最后一步中会出现此错误。

Obtain an IP address from the IP name of the site (the site URL without the leading 'http://'). This lookup (conversion of IP name to IP address) is provided by domain name servers (DNSs). Open an IP socket connection to that IP address. Write an HTTP data stream through that socket. Receive an HTTP data stream back from the Web server in response. This data stream contains status codes whose values are determined by the HTTP protocol. Parse this data stream for status codes and other useful information. This error occurs in the final step above when the client receives an HTTP status code that it recognises as '300'.

修复300错误 - 一般

Fixing 300 errors - general

您应该做的第一件事是在Web浏览器中检查您的URL。如果
你看到某种网页提示你进一步的
操作/选择,那么你现在的URL对于Web服务器要处理的
来说还不够详细。

The first thing you should do is check your URL in a Web browser. If you see some kind of Web page prompting you for further action/choices, then your URL as it stands is not detailed enough for the Web server to process.

修复300错误 - CheckUpDown

Fixing 300 errors - CheckUpDown

如果
给了我们一个顶部,你应该永远不会在你的CheckUpDown账户上看到这个错误-level URL(如www.isp.com)来检查。如果顶级URL出现
,则很可能是Web服务器
软件编程或配置错误。如果您有
给我们一个低级别的URL(例如www.isp.com/products/index.html)到
check,那么很可能这个URL甚至不能通过$来访问b $ b Web浏览器。

You should never see this error on your CheckUpDown account if you gave us a top-level URL (such as www.isp.com) to check. If it does occur for a top-level URL, it is highly likely that the Web server software has been incorrectly programmed or configured. If you have given us a low-level URL (such as www.isp.com/products/index.html) to check, then it is likely that this URL is not accessible even via a Web browser.

您应该做的第一件事是在Web浏览器中检查您的URL。如果
你看到一个合理的网页,那么它可能表明我们的
软件存在缺陷。但是,如果您看到某种类型的网页提示您进行
进一步操作/选择,那么您的网址不适合我们检查,
因为我们的系统无法做出这种选择。

The first thing you should do is check your URL in a Web browser. If you see a sensible Web page, then it may indicate a defect in our software. If however you see some kind of Web page prompting you for further action/choices, then your URL is not suitable for us to check, because our system can not possibly make this kind of choice.

如果遇到
300错误,请直接联系我们(首选电子邮件)。只有我们可以为您解决它们。如果
我们的软件存在缺陷,我们会修复它。但是,如果您的网址从根本上不适合我们使用
,则需要在CheckUpDown帐户中进行更改(以
开头点击管理按钮)。

Please contact us directly (email preferred) whenever you encounter 300 errors. Only we can resolve them for you. If there is a defect in our software we will fix it. If however your URL is fundamentally unsuitable for us to use, you need to change it on your CheckUpDown account (start by clicking the 'Manage' button).


推荐答案

Google使用 302 Found 重定向到本地化页面。

Google uses 302 Found for redirection to localised page.

我认为如果谷歌使用它是安全的...

I think it is safe if Google uses it...

但是,检查选择的响应应该做什么总是好的它的用途是什么,它是否会影响缓存:

However, it's always good to check what selected response should do and what it is intended for and does it affect caching:

http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

这篇关于用于语言重定向的HTTP状态代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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