简体   繁体   English

PHP 301重定向,不可能?

[英]PHP 301 Redirect, Impossible?

I have been trying to do a proper 301 redirect and have failed to do so. 我一直在尝试进行适当的301重定向,但未能这样做。 No matter what i try, its always a 302 redirect. 无论我尝试什么,它总是302重定向。

Returns a 302: 返回302:

http_redirect("urlgoeshere", '', false, HTTP_REDIRECT_PERM)

Returns a 302: 返回302:

header("HTTP/1.1 301 Moved Permanently");
header("Location: urlgoeshere");

Can anyone explain why these are coming back as 302's and not 301's? 任何人都可以解释为什么这些回归302而不是301? Server OS is linux, running PHP/5.2.14. 服务器操作系统是linux,运行PHP / 5.2.14。 Try it yourself. 亲自尝试一下。

I will give you guys a URL to try. 我会给你们一个URL尝试。 I am testing using YSlow and Googlebot. 我正在使用YSlow和Googlebot进行测试。

Should be 301: http://www.fantasysp.com/player/mlb/Albert_Pujols/1486349 应该是301: http//www.fantasysp.com/player/mlb/Albert_Pujols/1486349

Firebug显示302 Code

Pretty straightforward actually: 实际上很简单:

header('Location: ' . $url, true, 301);

在此输入图像描述


If you're using FastCGI try doing this instead: 如果你正在使用FastCGI,请尝试这样做:

header('Status: 301 Moved Permanently', true);
header('Location: ' . $url); // or header('Location: ' . $url, true, 301);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM