Jump to content

header() does not seem to work correctly (read the stickey)


leesiulung

Recommended Posts

I use the following code to redirect:

 

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.mydomain.com/");
exit();
?>

 

However, when checking the headers sent, the text after the code 301 gets chopped off. I tried different codes too...

 

Can anyone see anything wrong with this? I eventually solved it by using .htaccess file instead, but would like to get to the bottom of this.

Maybe try

 

<?php
header("HTTP/1.0 301 Moved Permanently");
header("Location: http://www.mydomain.com/");
exit();
?>

 

Other than that it seems like it should work to me.

 

 

EDIT:

 

Found this on www.php.net/header in the user comments:

jherman at digitalgravy dot net

17-May-2006 05:16

PHP as CGI treats header differently.

 

header("HTTP/1.0 404 Not Found"); returns "404 ok"

 

When using PHP (3,4 and 5) as CGI to return a 404 you need to use:

 

header("Status: 404 Not Found"); this returns "404 Not Found"

 

See: http://bugs.php.net/bug.php?id=27345

 

Perhapd you have PHP installed as CGI?

Yeah, it is installed as a CGI.

 

However, in my case the header returned is:

 

header("HTTP/1.0 301 Moved Permanently"); -> "HTTP/1.0 301"

 

Incomplete header... Is that the same problem as the '404 ok' error header you suggested?

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.