301 redirect using htaccess or php which one is best

Discussion in 'PHP' started by scriptreseller, Nov 1, 2008.

  1. #1
    Hi

    I run a large social network and i am changing its domain. But i wont all the the links that point to the current domain to work ( there are lots )

    So i am wanting to know how best to do it in terms so the search engines pass all over my current rankings from my old domain to my new on.

    here is an example of what i need to do.

    www.olddomain.co.uk/username

    i need that to divert to

    www.newdomain.com/username

    with out having to list very user and page in my old site hope i am explaining it properly.

    Thanks
     
    scriptreseller, Nov 1, 2008 IP
  2. sandstorm140

    sandstorm140 Peon

    Messages:
    80
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'm not a search engine pro, but as far as I know, most spiders/robots hate redirects. I'v always kept the old domain for a few more months with just a simple link stating the page has moved. It has always worked pretty well for me.
     
    sandstorm140, Nov 1, 2008 IP
  3. scriptreseller

    scriptreseller Active Member

    Messages:
    323
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Not if it is done right 301 redirects are designed for this type of thing simply putting a link up is not going to work we have over 40,000 members we need to do a redirect its just finding out which way best to do it
     
    scriptreseller, Nov 1, 2008 IP
  4. sandstorm140

    sandstorm140 Peon

    Messages:
    80
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    sandstorm140, Nov 1, 2008 IP
  5. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #5
    
    //also take note of the $_SERVER['QUERY_STRING']; as it will return the a=5&id=4 vars.
    
    $fulluri = 'http://www.new-url.com'. $_SERVER['REQUEST_URI'];
    header( "HTTP/1.1 301 Moved Permanently" );
    header( $fulluri );
    exit;
    
    PHP:
     
    exodus, Nov 1, 2008 IP
  6. JWRmedia

    JWRmedia Banned

    Messages:
    499
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #6
    htaccess is more secure. The php redirect may not always work depending on the browser and browser settings.

    Use htaccess.
     
    JWRmedia, Nov 1, 2008 IP
  7. keyaa

    keyaa Peon

    Messages:
    137
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #7
    the .htaccess / mod_rewrite way is a bit faster, if that matters to you.
     
    keyaa, Nov 1, 2008 IP
  8. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #8
    For your situation I would have Apache (htaccess) do it.

    Apache and PHP are doing pretty much the same thing to issue the redirect.
    however, doing it with PHP is like getting out of your car, walking through the house and into the garage then opening the garage door from inside instead of just clicking the remote opener clipped to your sun visor.
     
    joebert, Nov 1, 2008 IP
  9. scriptreseller

    scriptreseller Active Member

    Messages:
    323
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #9
    Thanks I think i will go with the htaccess then any tips on what we need to put in the htaccess file.

    Thanks
     
    scriptreseller, Nov 2, 2008 IP
  10. keyaa

    keyaa Peon

    Messages:
    137
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #10
    .htaccess
    RewriteEngine On
    RewriteCond %{HTTP_HOST} www.olddomain.co.uk
    RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]
    Code (markup):
     
    keyaa, Nov 2, 2008 IP