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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.