Redirect Question for my site.

Discussion in 'Programming' started by noobie2shoes, Jun 2, 2008.

  1. #1
    Basic Redirect noob question.

    I have searched for some old threads regarding this but cant seem to find anything.

    I know you have to enter code for the redirect:

    For example where would I enter the below code? Into what file in my root directory?:confused::confused:

    header("HTTP/1.1 301 Moved Permanently");
    header("Location: http://www.newdomain.com/newpage.html");
    exit();
    ?>

    Please note that the domain i would like to redirect from has no site on it at the moment and is just a domain name with hosting.
     
    noobie2shoes, Jun 2, 2008 IP
  2. mehmetm

    mehmetm Well-Known Member

    Messages:
    134
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #2
    hi,

    you can do this using that code in htaccess.

    RewriteRule ^oldpage.html?$ http://www.newdomain.com/newpage.html? [R=301]
     
    mehmetm, Jun 2, 2008 IP
  3. TechnoGeek

    TechnoGeek Peon

    Messages:
    258
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The code you posted seems to be PHP. PHP is a script language for coding Web pages, so you should create a page with the name that you want to be redirected. For instance, you want this:

    page001.php --> page002.php

    The code shown should be in page001.php. Note that the name must end in .php and be sure to include "<?php" as the first line.

    Another option is to use a redirect line in .htaccess, like this:

    Redirect 301 page001.php /page002.php

    Here the names can be anything.

    Hope this helps.
     
    TechnoGeek, Jun 2, 2008 IP
  4. noobie2shoes

    noobie2shoes Peon

    Messages:
    704
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Ok lets say....

    I have a domain with nothing on it at all no file or anything.

    Would the best way for me to redirect that domain be by creating .htaccess file then inserting the correct code ?:confused:
     
    noobie2shoes, Jun 3, 2008 IP
  5. mehmetm

    mehmetm Well-Known Member

    Messages:
    134
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #5

    using .htaccess is the easy and short way..
     
    mehmetm, Jun 3, 2008 IP
  6. noobie2shoes

    noobie2shoes Peon

    Messages:
    704
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #6
    OK.

    Therefore....the I should create .htaccess file and past the code into it ?

    IS that way its done ?
     
    noobie2shoes, Jun 3, 2008 IP
  7. TechnoGeek

    TechnoGeek Peon

    Messages:
    258
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #7
    The .htaccess is usually already present as it is created by the system administrator. It contains nothing, its length is zero. Via FTP you can modify it, adding any of the redirect commands you were taught. Then test if the redirect works using your browser. If you have no files in the source domain, maybe the best option is:

    Redirect permanent / http://www.targetdomain.com
     
    TechnoGeek, Jun 4, 2008 IP