PHP 301 Redirect, Impossible?

浪子不回头ぞ 提交于 2019-12-18 11:48:41

问题


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.

Returns a 302:

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

Returns a 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? Server OS is linux, running PHP/5.2.14. Try it yourself.

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

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


回答1:


Pretty straightforward actually:

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


If you're using FastCGI try doing this instead:

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


来源:https://stackoverflow.com/questions/5268454/php-301-redirect-impossible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!