PHP 301重定向,不可能吗? [英] PHP 301 Redirect, Impossible?

查看:96
本文介绍了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);

这篇关于PHP 301重定向,不可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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