301 PHP redirect not working

Discussion in 'HTML & Website Design' started by InnovationZen, Oct 7, 2006.

  1. #1
    My goal: redirect www.innovationzen.com to innovationzen.com

    I inserted the following code right at the top of the header.php
    _______________________
    <?php

    if ($_SERVER['HTTP_HOST'] == "www.innovationzen.com") {
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: http://innovationzen.com".$_SERVER['REQUEST_URI']);
    exit; }
    ?>
    ____________________________

    However the redirect is not working, when i hit www.innovationzen.com I get the following:

    "The document has moved here.

    Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request."


    Does anyone know what is wrong with the redirect?

    thanks
     
    InnovationZen, Oct 7, 2006 IP
  2. iatbm

    iatbm Prominent Member

    Messages:
    5,151
    Likes Received:
    352
    Best Answers:
    0
    Trophy Points:
    360
    #2
    Something like this ?

    RewriteCond Host: www\.mysite\.com
    RewriteRule (.*) http\://mysite.com$1 [I,R]
     
    iatbm, Oct 7, 2006 IP
  3. InnovationZen

    InnovationZen Well-Known Member

    Messages:
    285
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    108
    #3
    i need to do a php redirect becayse my host (yahoo) does not support .htaccess

    I know it sucks but I am trying to set up the php before taking the more drastic action of changing host
     
    InnovationZen, Oct 7, 2006 IP
  4. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #4
    Not tested.

    Move exit; outside the if statement.
    
    <?php if ($_SERVER['HTTP_HOST'] == "www.innovationzen.com") {
       header("HTTP/1.1 301 Moved Permanently");
       header("Location: http://innovationzen.com".$_SERVER['REQUEST_URI']);
    }
    exit;
    ?>
    Code (markup):
    Oh, and remove the empty line at the start. It matters in the header.
    cheers,

    gary
     
    kk5st, Oct 7, 2006 IP
  5. InnovationZen

    InnovationZen Well-Known Member

    Messages:
    285
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    108
    #5
    InnovationZen, Oct 7, 2006 IP