Redirect

Discussion in 'PHP' started by goodmast3r, Mar 21, 2009.

  1. #1
    goodmast3r, Mar 21, 2009 IP
  2. steelaz

    steelaz Peon

    Messages:
    47
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    <?php header('Location: http://www.domain.com'); ?>
    PHP:
     
    steelaz, Mar 21, 2009 IP
  3. goodmast3r

    goodmast3r Active Member

    Messages:
    1,220
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    78
    #3
    Hi steelaz. Where should I put the code? Thanks.
     
    goodmast3r, Mar 21, 2009 IP
  4. Lpe04

    Lpe04 Peon

    Messages:
    579
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you are doing this for canonical purposes, then in your .htaccess

    In that case
    
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example.com
    RewriteRule (.*) http://www.example.com/$1 [R=301,L]
    
    Code (markup):
    in your htaccess.
     
    Lpe04, Mar 21, 2009 IP
  5. goodmast3r

    goodmast3r Active Member

    Messages:
    1,220
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    78
    #5
    goodmast3r, Mar 21, 2009 IP
  6. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #6
    That is because that is NOT a host. it is a directory. just use what he showed you and you will be fine.
     
    NatalicWolf, Mar 21, 2009 IP
  7. Lpe04

    Lpe04 Peon

    Messages:
    579
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Good answer, thanks ;)
     
    Lpe04, Mar 21, 2009 IP
  8. websea

    websea Peon

    Messages:
    572
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You can also do this by using java script. I don't have it right now but search for "location.replace('url here')". check this and try this may also work.
     
    websea, Mar 21, 2009 IP
  9. Lpe04

    Lpe04 Peon

    Messages:
    579
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #9
    wouldn't that redirect even on the www version?
     
    Lpe04, Mar 21, 2009 IP
  10. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Doing it with Javascript won't work for all users, and in particular it won't work for search engine crawlers.
     
    SmallPotatoes, Mar 21, 2009 IP
  11. vishal2241

    vishal2241 Active Member

    Messages:
    101
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #11
    HOW TO INJECT A COOKIE IN FACEBOOK IMAGES SO THAT IT WILL REDIRECT TO MYPAGE
     
    vishal2241, Mar 22, 2009 IP
  12. igor398

    igor398 Guest

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Use RewriteMode.
    it is better for SE
     
    igor398, Mar 22, 2009 IP
  13. Lpe04

    Lpe04 Peon

    Messages:
    579
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #13
    You will probably be banned.
     
    Lpe04, Mar 22, 2009 IP
  14. e2developer

    e2developer Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    I think htaccess is better option for redirection.
     
    e2developer, Mar 23, 2009 IP
  15. lazysurfer

    lazysurfer Peon

    Messages:
    28
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Try Here "Google" The first four results explain everything in detail.
     
    lazysurfer, Mar 23, 2009 IP
  16. Ilyesoft

    Ilyesoft Banned

    Messages:
    164
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Javascript is bad, use rewritemod, or tell your hosting company to do that,or use php.
    For the php why:
    1-read the current url
    2-if it starts with : http:// domain . com , replace it with h t t p : / / www . domain . com, save into new string
    3-header('location: " . $newurl );

    This is the idea, if you don't know how to read ur, replace ... we will help you.

    BUT ! You need to put that php script in all pages, I hope you use a header in a file
    if not use htaccess
     
    Ilyesoft, Mar 25, 2009 IP