Forum Moderators: coopster

Message Too Old, No Replies

Problems with 301 redirect

Not working...affecting Google duplicates

         

ianevans

3:39 am on Oct 31, 2006 (gmt 0)

10+ Year Member



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: [mysite.com...]
exit();

The header checker is returning this:

#1 Server Response: [mysite.com...]
HTTP Status Code: HTTP/1.0 302 Found
Connection: close
X-Powered-By: PHP/5.1.4
Location: [mysite.com...]

Is lightty causing the change to 302?

jdMorgan

4:01 am on Oct 31, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not much of a PHP coder myself, but I believe you need to add "Status:" to your 301 Moved Permanently header, just as you have added "Location:" to the second line.

Jim

ianevans

12:22 pm on Oct 31, 2006 (gmt 0)

10+ Year Member



Not according to the PHP specs. It's a real headbanger, because it is causing issues with old pages and google.

omoutop

1:16 pm on Oct 31, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Can't you use htaccess redirections?

Something like :

Options +FollowSymLinks
RewriteEngine on
RewriteOptions inherit

RewriteRule ^old_page(.*) $http://www.yoursite.com/path/to/old_page$1 [R=301,L]

Check the apache forum here in webmasterworld for more appropriate info on this.

Hope this helps

jatar_k

5:06 pm on Oct 31, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



jdMorgan is right on the money, though not directly

what happens is you pass the status, which you have correctly, then you send a location header and if you hadn't added a status before then it would default to a 302.

I would look at 2 things

the server header checker you used, make sure it is correct, though since you are having dupe issues it is probably right

make a small change to see if it makes any difference

header('HTTP/1.1 301 Moved Permanently');

change the double quotes to single quotes, the parser could be doing something funny and you definitely do not want that string parsed.

you need to look at that line because it looks like you are sending a malformed status header which is causing the second header to default to 302

ianevans

12:54 am on Nov 1, 2006 (gmt 0)

10+ Year Member



I tried changing the double quotes to single in the PHP, but lighttpd is still returning a 302 instead of a 301.

Could you sticky mail me the url of a header checker you'd recommend?

BTW, just did a wget on the page and rec'd a "HTTP request sent, awaiting response... 302 Found"

jatar_k

5:55 am on Nov 1, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



well, if wget gives you a 302, then it's a 302

that's weird, the syntax is right, though I admit I seldom do 301s with php, I do them with apache

ianevans

7:26 am on Nov 1, 2006 (gmt 0)

10+ Year Member



From doing a little digging, it appears that it's a problem with running php as fastcgi.

Still haven't found a solution that works.

jatar_k

5:46 pm on Nov 1, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



ahhh

I have actually heard that before

maybe try the rewrite route

ianevans

5:38 am on Nov 3, 2006 (gmt 0)

10+ Year Member



>maybe try the rewrite route

I'm not sure what you're saying...do you mean do it through the lighttpd config file rather than through php?

jatar_k

8:36 am on Nov 3, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if you can, yes, maybe as omoutop recommended above