301 redirect returning 302 instead

This is a discussion on 301 redirect returning 302 instead within the PHP General forums, part of the PHP Programming Forums category; Having a problem here trying to redirect some old pages. I've recently noticed using a server header check that ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-01-2006
ianevans@digitalhit.com
 
Posts: n/a
Default 301 redirect returning 302 instead


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
Reply With Quote
  #2 (permalink)  
Old 11-04-2006
Chris Shiflett
 
Posts: n/a
Default Re: [PHP] 301 redirect returning 302 instead

ianevans@digitalhit.com wrote:
> header('HTTP/1.1 301 Moved Permanently');
> header('Location: newurl');
> exit();


If you're using PHP 4.3 or later, header() lets you set the response
status code with the third argument. Otherwise, sending a Location
header sets the response status code to 302.

If you're using an old version of PHP, you should try reversing the
order of the header() calls in your example, if you haven't already.

Hope that helps.

Chris

--
Chris Shiflett
http://shiflett.org/
Reply With Quote
  #3 (permalink)  
Old 11-05-2006
ianevans@digitalhit.com
 
Posts: n/a
Default Re: [PHP] 301 redirect returning 302 instead

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.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:30 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0