PHP 301重定向,不可能吗?

PHP 301重定向,不可能吗?

问题描述:

我一直在尝试执行适当的301重定向,但未成功执行.不管我尝试什么,它始终是302重定向.

I have been trying to do a proper 301 redirect and have failed to do so. No matter what i try, its always a 302 redirect.

返回302:

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

返回302:

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

谁能解释为什么它们又回到302,而不是301?服务器操作系统是linux,运行PHP/5.2.14.自己尝试.

Can anyone explain why these are coming back as 302's and not 301's? Server OS is linux, running PHP/5.2.14. Try it yourself.

我会给你们一个URL尝试.我正在使用YSlow和Googlebot进行测试.

I will give you guys a URL to try. I am testing using YSlow and Googlebot.

应为301: http://www.fantasysp.com/player/mlb/Albert_Pujols/1486349

实际上非常简单:

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

如果您使用的是FastCGI,请尝试执行以下操作:

If you're using FastCGI try doing this instead:

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