[PHP] 301 redirect returning 302 instead

2006-10-31 Thread ianevans

Having a problem here trying to redirect some old pages.

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('HTTP/1.1 301 Moved Permanently');
header('Location: newurl');
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: newurl

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.

BTW, my server is lighttpd.

-- 
Ian Evans
Chairman & Executive Producer
DigitalHit.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 301 redirect returning 302 instead

2006-11-01 Thread ianevans
> Just a shot in the dark, but it's possible that providing a "Location"
> header resets the status response. Try swapping your two header calls.

Stut:
Flipping the headers doesn't work, unfortunately, running wget still shows
a 302 being returned.

Kris:
You need both headers. Just giving the Location would give a 302, when a
301 is the goal.

Just to add more info: We're running php as fastcgi under lighttpd. Doing
a little searching I see that there is some weirdness with http headers
when PHP is run as a CGI, but I can't seem to see any solutions out there.
Obviously I can't be the ONLY person running this way, so there has to be
a solution out there.

-- 
Ian Evans
Chairman & Executive Producer
DigitalHit.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 301 redirect returning 302 instead

2006-11-01 Thread ianevans
> Write a quick-hack Perl script to just do a 301 and Location and see
> if Perl+lighthttpd gets you a 302 or a 301.

Did as you suggested and perl+lighttpd produces the 301 as expected.

So the unwanted 302 is just lighttpd+php.

This seems to be connected to http://bugs.php.net/bug.php?id=36705

-- 
Ian Evans
Chairman & Executive Producer
DigitalHit.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 301 redirect returning 302 instead

2006-11-01 Thread ianevans
> what version of php?

PHP 5.1.4 (cgi-fcgi)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 301 redirect returning 302 instead

2006-11-02 Thread ianevans
Still scratching my head on this one...

According to what I've read, when php is run as a CGI then a Status:
number text header should be set instead. Add to that the header docs on
the php site say that "The second special case is the "Location:" header.
Not only does it send this header back to the browser, but it also returns
a REDIRECT (302) status code to the browser unless some 3xx status code
has __already been set__."

Adding those two bits together, this code SHOULD work:

header("Status: 301 Moved Permanently");
header('Location: newurl');

I've even tried using the other format:
header("Location: newurl",1,301);

No matter what, I get a 302 instead of a 301.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 301 redirect returning 302 instead

2006-11-04 Thread ianevans
Chris,

I just posted this to php-internals in response to someone else, but this
tale of woe shows the problem:

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.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] 301 redirect returning 302 instead

2006-11-06 Thread ianevans
Just upgraded to 5.2.0 and alas, the 301/302 issue still exists. Guess
I'll head off to bugs.php.net

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php