Problems with 301 redirects

php.internals

Unnamed Person

19 years ago
Someone on the php-general list suggested I write here before submitting this to bugs.php.net to see if it was a known issue. Having a problem here trying to redirect some old pages. Running php 5.1.4 as fastcgi under lighttpd. I've recently noticed using a server header check that my 301 redirects in PHP are returning 302 instead. I'm using the following code: header("Status: 301 Moved Permanently"); header("Location: mynewurl"); exit(); The header checker is returning this: #1 Server Response: oldurl HTTP Status Code: HTTP/1.0 302 Found Connection: close X-Powered-By: PHP/5.1.4 Location: mynewurl Any reason why we're getting a 302 instead of a 301? This is keeping the pages in Google instead of removing them and using the new location. As per suggestions on the general list I've tried the status line before and after the location. I've used the HTTP version instead of the "Status:" etc.
-- Ian Evans Chairman & Executive Producer DigitalHit.com -- Ian Evans Chairman & Executive Producer DigitalHit.com -- Ian Evans Chairman & Executive Producer DigitalHit.com

Unknown W. Brackets

19 years ago
Shouldn't you use... header('HTTP/1.0 301 Moved Permanently'); header('Location: http://...'); That is what I've always used and it's worked for me. Additionally, the method you have suggested does not work for me. -[Unknown] -------- Original Message --------

Michael Wallner

19 years ago
ianevans@digitalhit.com wrote:
> I'm using the following code: > > header("Status: 301 Moved Permanently"); > header("Location: mynewurl"); > exit();
Never ever use a Status header. Either set the third param to header() to the intended response status code or use a "HTTP/1.1 301" header string. See http://php.net/header
-- Michael

Unnamed Person

19 years ago
> Never ever use a Status header.
As I mentioned in my email, I have used the HTTP string: header("HTTP/1.1 301 Moved Permanently"); header("Location: http://..."); exit(); produces a 302. header("Location: http://..."); header("HTTP/1.1 301 Moved Permanently"); exit(); produces a 302. header("Location: http://...",false,301); produces a 302 and, for good luck, header("Location: http://...",true,301); produces a 302. Everything's producing a 302. So you can see the dilemma.

dAniel hAhler

19 years ago
ianevans@digitalhit.com wrote:
> header("Location: http://...",false,301);
This works here with PHP 5.1.7-dev and 5.2.1-dev and mod_fastcgi. Have you tried just that line? Without any HTTP/-header?

Unnamed Person

19 years ago
>> header("Location: http://...",false,301); > This works here with PHP 5.1.7-dev and 5.2.1-dev and mod_fastcgi. > Have you tried just that line? Without any HTTP/-header?
I've tried every combination. Just tried it again and it still returns a 302. BTW, not using mod_fastcgi as we're not running Apache...we're running lighttpd.
-- Ian Evans Chairman & Executive Producer DigitalHit.com

Edin Kadribasic

19 years ago
ianevans@digitalhit.com wrote:
>>> header("Location: http://...",false,301); >>> >> This works here with PHP 5.1.7-dev and 5.2.1-dev and mod_fastcgi. >> Have you tried just that line? Without any HTTP/-header? >> > > I've tried every combination. Just tried it again and it still returns a 302. > > BTW, not using mod_fastcgi as we're not running Apache...we're running > lighttpd.
It is possible that this could be an issue with interaction between PHP and lighttpd. I would contact the lighttpd folks and see if this might be the case. I had some issues with headers and redirects using lighttpd which turned out to be problems with the web server itself. Edin