How to redirect a URL in php

Discussion in 'PHP' started by devat, Mar 18, 2008.

  1. #1
    devat, Mar 18, 2008 IP
  2. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #2
    you want it to redirect permanently, temporarily etc for the search bots and all?

    or do you just want a simple code to redirect without affecting much else?

    if you just want the code it has to come before Headers. (at the very top of your page -whatever you use, i use notepad, so at top of notepad.. with no space ...begin code at the FIRST line

    something like this
    <?php header('location: http://www.yourredirectsite.com'); ?>

    When that page loads, it'll read that code, and redirect.
    You can use that code anywhere in your PHP scripts .. AS LONG AS your scripts dont echo, print, or write or perform any functions on that page. Otherwise you'll get the error = Error : Headers already sent ..blah blah
     
    ezprint2008, Mar 18, 2008 IP
  3. NoamBarz

    NoamBarz Active Member

    Messages:
    242
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #3
    NoamBarz, Mar 18, 2008 IP
  4. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #4
    If you want to redirect non-www to www.
    theres a way to do it in the .httaccess

    BUT.. many say its not a good thing to do ..since search engines keep track of both non-www and www
    and thatit could perhaps shut down half or more of your traffic.
    I never got into it enough to see if it did any damage.

    But the code looks like this in .htaccess
    also want to probably skip a line at last line on .htacces


    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^yoursite.com [NC]
    RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]
     
    ezprint2008, Mar 18, 2008 IP
  5. devat

    devat Peon

    Messages:
    670
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    hello ezprint2008

    i can already put these code [ non www to www ] into my .htaccess file and working perfectly

    suppose u can open my site link : http://www.online-web-ratings.com/ than u can remove the www so it can redirect direct the www [ so is it working ]

    but i want to redirect inner pages like : http://www.online-web-ratings.com/web-design-ratings/ to http://www.online-web-ratings.com/web-design-ratings [ without / ]

    so in these above code which new line add and give some new code for removing / and than working perfectly

    also provide me new .htaccess code for these query

    thanks a lot for give me suggection for non www to www

    p'se reply ASAP
     
    devat, Mar 19, 2008 IP
  6. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #6
    to remove the / from the end?

    type some of these:
    yahoo.com
    google.com
    youtube.com

    check out what happens to the end of their URL
     
    ezprint2008, Mar 20, 2008 IP