1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Redirect Help

Discussion in 'PHP' started by MakeThatDollar, Dec 23, 2008.

  1. #1
    How can I redirect somepage.php?location=125 to page.php?

    I tried the following, but it didn't work:

    Redirect 301 /somepage.php?location=125 http://www.domain.com/page.php

    Please help! Thanks.
    SEMrush
     
    MakeThatDollar, Dec 23, 2008 IP
    SEMrush
  2. harrisunderwork

    harrisunderwork Well-Known Member

    Messages:
    1,005
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    135
    #2
    harrisunderwork, Dec 23, 2008 IP
    MakeThatDollar likes this.
  3. MakeThatDollar

    MakeThatDollar Notable Member Premium Member

    Messages:
    4,451
    Likes Received:
    157
    Best Answers:
    0
    Trophy Points:
    225
    #3
    Hmm I tried that, but it says, "The requested URL /somepage.php was not found on this server." just like it was before.

    Any ideas?
     
    MakeThatDollar, Dec 23, 2008 IP
  4. hackfanatic

    hackfanatic Peon

    Messages:
    29
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Have you tried this ?

    <?php

    header('Location: page.php');

    ?>
     
    hackfanatic, Dec 23, 2008 IP
  5. MakeThatDollar

    MakeThatDollar Notable Member Premium Member

    Messages:
    4,451
    Likes Received:
    157
    Best Answers:
    0
    Trophy Points:
    225
    #5
    Thanks hackfanatic.. but that won't work in my case. I need to utilize htaccess features.
     
    MakeThatDollar, Dec 23, 2008 IP
  6. hackfanatic

    hackfanatic Peon

    Messages:
    29
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    i think the "?" in the RewriteRule creates an issue.

    Try This

    RewriteEngine on
    RewriteCond %{QUERY_STRING} location=(.*)
    RewriteRule ^(.*)somepage.php$ page.php?q=%1 [L]
     
    hackfanatic, Dec 23, 2008 IP
  7. MakeThatDollar

    MakeThatDollar Notable Member Premium Member

    Messages:
    4,451
    Likes Received:
    157
    Best Answers:
    0
    Trophy Points:
    225
    #7
    Thanks, that seems to be working.

    However... I do have more than one location.. for example ( location=125 goes to page.php ) and location=126 would go to simple.php and so on.

    Can I replace (.*) with the number or would that not work?

    How would I do that correctly?
     
    MakeThatDollar, Dec 23, 2008 IP
  8. hackfanatic

    hackfanatic Peon

    Messages:
    29
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Yes,

    That would work,

    The final script would be like

    RewriteEngine on
    RewriteCond %{QUERY_STRING} location=125
    RewriteRule ^(.*)somepage.php$ page1.php [L]
    RewriteCond %{QUERY_STRING} location=126
    RewriteRule ^(.*)somepage.php$ page2.php [L]
     
    hackfanatic, Dec 23, 2008 IP
    MakeThatDollar likes this.
  9. MakeThatDollar

    MakeThatDollar Notable Member Premium Member

    Messages:
    4,451
    Likes Received:
    157
    Best Answers:
    0
    Trophy Points:
    225
    #9
    MakeThatDollar, Dec 23, 2008 IP