Simple PHP redirect Issue

Discussion in 'PHP' started by evelinawilliams007, Apr 2, 2009.

  1. #1
    Hey guys,

    I am a novice in PHP and I'm trying to redirect a .html page of my site (only a single page) using PHP redirect.

    Here's the code I use:

    <?php
    header("Location: http://www.domainname.com");
    exit;
    ?>


    Am I supposed to simply place this PHP code into the .html file and remove all its content and then upload the file?

    Because this is what I've done and it's still not working. I get a blank white page. Can anyone please give me a hand?

    Thanks a lot
     
    evelinawilliams007, Apr 2, 2009 IP
  2. seoz

    seoz Banned

    Messages:
    229
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2

    put this code in your that html file and remove all codes . Make a backup of that page before doing this. incase it wont work upload th eold page again. :)

    ----------

    <?
    Header( "HTTP/1.1 301 Moved Permanently" );
    Header( "Location: http://www.YOURWEBITE.com" );
    ?>
     
    seoz, Apr 2, 2009 IP
  3. evelinawilliams007

    evelinawilliams007 Notable Member

    Messages:
    3,120
    Likes Received:
    58
    Best Answers:
    0
    Trophy Points:
    210
    Articles:
    6
    #3
    Thanks but it still doesn't work ..
    Have no idea why because all the tutorials I've read so far explain the exact same method..

    Anybody knows another way of redirecting a .html page using PHP?

    Thanks
     
    evelinawilliams007, Apr 2, 2009 IP
  4. seoz

    seoz Banned

    Messages:
    229
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    do you know bout .htaccess ??
    if you have access to this file than the things can be pretty easy
    here is the procedure

    To create a .htaccess file, open notepad, in the name field type .htaccess and save the file type as all files

    2. If you already have a .htaccess file on your server,
    download it to your desktop for editing.

    3. Place this code in your .htaccess file:

    redirect 301 /old/old.htm http://www.you.com/new.htm

    4. If the .htaccess file already has lines of code in it,
    skip a line, then add the above code.

    5. Save the .htaccess file

    6. Upload this file to the root folder of your server.

    7. Test it by typing in the old address to the page you've
    changed. You should be immediately taken to the new
    location.
     
    seoz, Apr 2, 2009 IP
  5. evelinawilliams007

    evelinawilliams007 Notable Member

    Messages:
    3,120
    Likes Received:
    58
    Best Answers:
    0
    Trophy Points:
    210
    Articles:
    6
    #5
    I can try this method as well, the thing I did not mention is that I want to redirect the page to another domain. (a vendor's domain) -- redirecting with my affiliate link is it the same thing?
     
    evelinawilliams007, Apr 2, 2009 IP
  6. seoz

    seoz Banned

    Messages:
    229
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    yup it works same :)
     
    seoz, Apr 2, 2009 IP
  7. evelinawilliams007

    evelinawilliams007 Notable Member

    Messages:
    3,120
    Likes Received:
    58
    Best Answers:
    0
    Trophy Points:
    210
    Articles:
    6
    #7
    Tx .. I've managed to do it using a simple html redirect.

    <html>
    <head>
    <meta HTTP-EQUIV="REFRESH" content="0; url=http://www.domain.com">
    </head>


    First I've removed all the code from the page (if all the initial code remains there and this html redirect is being used then the initial page appears before the actual redirected page so it's pretty useless)
     
    evelinawilliams007, Apr 2, 2009 IP
  8. seoz

    seoz Banned

    Messages:
    229
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    its not a permanent redirect and Google don't think its a good thing to do so be careful :)
     
    seoz, Apr 2, 2009 IP
  9. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #9
    Just a question - when you tried to add the PHP-code the first time around - did you change the .html extension of the file to .php? Unless you did, it won't work.
     
    PoPSiCLe, Apr 2, 2009 IP
  10. cool_fp

    cool_fp Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I think you have to try refresh code that would be helpful you.
     
    cool_fp, Apr 2, 2009 IP