PHP redirects

Discussion in 'PHP' started by Jim bob 9 pants, Dec 16, 2005.

  1. #1
    basically I want to establish within each php file how the request came, can I examine the requested url for whether it's a new version, or old version.
    if it's an old version, then output this code

    <?php
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: http://www.yourdomain.com/newpath");
    exit();
    ?>

    If I use this code as it stands i get
    Thank You

    Jamie
     
    Jim bob 9 pants, Dec 16, 2005 IP
  2. HN Will

    HN Will Guest

    Messages:
    111
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I guess my question would be why not do this in htaccess?
     
    HN Will, Dec 16, 2005 IP
  3. Jim bob 9 pants

    Jim bob 9 pants Peon

    Messages:
    890
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I have tried and get the same resuts I wonder if I am gettng this all wrong,

    I had a url

    www.mysite/germanpointersinengland.php

    and used a rewrite on that page to make the url

    www.mysite/german/pointers/in/england/

    so now both URLs find the same page, the site with its old URL's is well indexed in Google, Yahoo etc.

    I guess that a redirect might be trying to point to itself, hence not working. I am getting confused with it all. Any help would b great.

    Jamie
     
    Jim bob 9 pants, Dec 16, 2005 IP
  4. HN Will

    HN Will Guest

    Messages:
    111
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    What exactly do you mean by "old version" and "new version"?
     
    HN Will, Dec 16, 2005 IP
  5. fsmedia

    fsmedia Prominent Member

    Messages:
    5,163
    Likes Received:
    262
    Best Answers:
    0
    Trophy Points:
    390
    #5
    There's no reason to use exit(); you can get rid of that. using Header("Location:"); is enough. But yes, it should have something to do with .htaccess if you're getting a URL excess limit error.
     
    fsmedia, Dec 16, 2005 IP
  6. Jim bob 9 pants

    Jim bob 9 pants Peon

    Messages:
    890
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The old urls are indexed, as well as people deep linking to my pages, I need to keep all those links!

    If I have 2URLs pointing to the same pagewont dear old google penalize the site for dupe content

    Jamie

    edit - I just re-read my first post - i was thinking that if a post re-write URL was accessing the page the I could show the new url some how (probably aload of bollocks)
     
    Jim bob 9 pants, Dec 16, 2005 IP
  7. kirpy

    kirpy Member

    Messages:
    61
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    48
    #7
    I am using like 1mb .htaccess for this thing Jim se's still don't forget my old page urls. I am trying to find a solution for that in these days. But many se's don't like redirections so i suggest you use .htaccess too.
     
    kirpy, Dec 16, 2005 IP
  8. Jim bob 9 pants

    Jim bob 9 pants Peon

    Messages:
    890
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Can I have an example of a rewrite and redirect, mine work but i wonder if I am doing somthing wrong
     
    Jim bob 9 pants, Dec 17, 2005 IP
  9. Jim bob 9 pants

    Jim bob 9 pants Peon

    Messages:
    890
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I have now tried 301's in PHP and .htaccess and everytime I get

     
    Jim bob 9 pants, Dec 17, 2005 IP
  10. webdesign2005

    webdesign2005 Guest

    Messages:
    26
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #10
    webdesign2005, Dec 17, 2005 IP
  11. Jim bob 9 pants

    Jim bob 9 pants Peon

    Messages:
    890
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I will try that now

    If I type in the old url in the address bar I assume it will not change

    ie http://www.mysite/germanpointersinengland.php$ would show the page but would not change to http://www.mysite/german/pointers/in/england/

    is that correct?
     
    Jim bob 9 pants, Dec 17, 2005 IP
  12. Jim bob 9 pants

    Jim bob 9 pants Peon

    Messages:
    890
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #12
    I get again with that method, here is the script re that rewrite

    RewriteRule ^cornwall$ /AccommodationCornwall.php [L]
    RedirectMatch permanent ^/AccommodationCornwall.php$ http://www.test.visitdevonandcornwall.co.uk/cornwall
     
    Jim bob 9 pants, Dec 17, 2005 IP
  13. Jim bob 9 pants

    Jim bob 9 pants Peon

    Messages:
    890
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Jim bob 9 pants, Dec 17, 2005 IP
  14. cornelius

    cornelius Peon

    Messages:
    206
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #14
    ur are redirecting back to the same page! its a sort of a loop!
     
    cornelius, Dec 20, 2005 IP
  15. dave487

    dave487 Peon

    Messages:
    701
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #15
    If you do a mod rewrite then you can't contunue to use the same script you were using for the old page. If you try to do this then you will get an infinite loop of one page redirecting to another.

    The only solution is to use a different php script for the new page and then redirect the old page to the new friendly url.
    eg oldpage.php3 redirects to /file/newpage/55 which uses mod rewrite to call the script newpage.php3
     
    dave487, Dec 20, 2005 IP
  16. Jim bob 9 pants

    Jim bob 9 pants Peon

    Messages:
    890
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Thanks, this is what i am doing now
     
    Jim bob 9 pants, Dec 20, 2005 IP