Redirected link

Discussion in 'PHP' started by Omzy, Jan 20, 2009.

  1. #1
    In my file search.php, I have got it programmed so that it reads the value of $_GET['category']. It then matches that value with an array called $cats, if the value exists in $cats it displays some data on the page. If it does not exist, it redirects the user to another page (directory.php), using the php header() function.

    Now lets say I have a URL as such:

    /search.php?category=hotels

    This got indexed by Google but recently I changed the category 'hotels' to 'uk_hotels'.

    So now if anybody clicks the indexed link in Google, it redirects the user to 'directory.php'.

    Does anybody know how this change will affect the Google link when it does a refresh of the index, i.e will it display the title of the page it is redirecting to or will it just leave everything as it is?
     
    Omzy, Jan 20, 2009 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    When Google next spiders your site, it'll update just fine.

    Could always add an exception to handle the hits coming from Google.

    Dan.
     
    Danltn, Jan 20, 2009 IP
  3. Omzy

    Omzy Peon

    Messages:
    249
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks.

    OK I just did a test for that redirected URL on http://www.rexswain.com/httpview.html

    It says it's a 302 redirect, which is fine, however it seems to be processing the whole search.php file even though I've got the header() redirect code before it even includes the template file. Anybody know what's going on there?
     
    Omzy, Jan 20, 2009 IP
  4. Omzy

    Omzy Peon

    Messages:
    249
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Anybody got any idea?
     
    Omzy, Jan 21, 2009 IP
  5. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #5
    Add a die/exit after the header.

    Or combine them...
     
    Danltn, Jan 21, 2009 IP
  6. Omzy

    Omzy Peon

    Messages:
    249
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Cheers, I'll try that. It doesn't make sense though, I thought as soon as it encounters the header function it would stop processing the rest of the code and just process whatever the header function tells it to do!
     
    Omzy, Jan 21, 2009 IP
  7. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #7
    No, sending a header does not stop code execution, most regular browsers (e.g. Firefox) will simply redirect immediately. They will ignore content.

    It will still display though, which is a good opportunity to display a regular hyperlink for those browsers (and robots) which do not follow Location: (or similar) headers correctly.

    Dan.
     
    Danltn, Jan 21, 2009 IP