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.

Htaccess Redirect Help

Discussion in 'Apache' started by Freddy63, Feb 15, 2013.

  1. #1
    Hey guys,

    I'm really struggling to write htaccess rules for dynamic pages. I've like 20 pages to redirect and hoping for someone to help me write code. What I want to do is redirect

    www.sp-lawoffice.co.il/text.php?lang=heb&id=4
    to
    http://www.sp-lawoffice.co.il/?page_id=205
    Code (markup):
    and redirect,
    www.sp-lawoffice.co.il/text.php?lang=heb&id=6
    to
    http://www.sp-lawoffice.co.il/?page_id=207
    Code (markup):
    anybody know how to do it? I have like more than 20 pages to redirect. Any help will be appreciated.

    Thanks!
     
    Last edited: Feb 15, 2013
    Freddy63, Feb 15, 2013 IP
  2. Xavier2013

    Xavier2013 Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #2

    If you're just "hard coding" these specific links shouldn't it be something like ...
    redirect 301 <from url> <to url>
    that should be it.

    If these are just examples of dynamic links: I don't think it's possible. If it was remotely possible with htaccess page_id would have to exist in the "from" url . It looks like you need to make some changes to your site code.
     
    Xavier2013, Feb 21, 2013 IP
  3. innozemec

    innozemec Active Member

    Messages:
    84
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    68
    #3
    and dynamic links can be redirected by htaccess but writing the rules will give you hard times..

    better modify your text.php file to redirect to the new url by adding somewhere on top:

    if($_GET['id]==4)
    {
    header('Location: http://dsssssss');
    exit;
    }
    elseif....
    Code (markup):
     
    innozemec, Feb 21, 2013 IP
  4. Xavier2013

    Xavier2013 Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #4
    Not with the example links he provided. If so, can you give us one ? I'm curious.

    good idea ...
     
    Xavier2013, Feb 21, 2013 IP
  5. innozemec

    innozemec Active Member

    Messages:
    84
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    68
    #5
    innozemec, Feb 21, 2013 IP
  6. Xavier2013

    Xavier2013 Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #6
    Yes, I know it's possible to capture variables with htaccess. Now give me an example with the links he provided? You can't because it's not possible like I said. :)
     
    Xavier2013, Feb 21, 2013 IP
  7. Xavier2013

    Xavier2013 Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #7
    He's trying to get a page_id=205 out of "lang=heb&id=4" ? Unless he wants to convert his page_id=4 . I'm just saying what he gave us isn't much to work with.
     
    Xavier2013, Feb 21, 2013 IP
  8. innozemec

    innozemec Active Member

    Messages:
    84
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    68
    #8
    from his examples i see the ids increment with 201 , so if thats true for all his links, whats the problem?
     
    innozemec, Feb 21, 2013 IP
  9. Xavier2013

    Xavier2013 Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #9
    If you feel so strongly no problem exists then you should be willing to provide an example with what he provided. You can't. Which was my point the first time I answered his question and you basically came in and just re-iterated my answer.
     
    Xavier2013, Feb 21, 2013 IP
  10. innozemec

    innozemec Active Member

    Messages:
    84
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    68
    #10
    I made my statement it is possible, because i saw the logic in the samples he gave that the IDs increment with 201. So, if thats true for all his links, here's the solution:

    RewriteEngine On
    RewriteCond %{QUERY_STRING} lang=heb&id=(.*)
    RewriteRule ^text\.php tmp.php?id=%1

    tmp.php contents:
    <?php
    header('Location: http://www.sp-lawoffice.co.il/?page_id='.(201+$_GET['id']));
    ?>
    Code (markup):
     
    innozemec, Feb 21, 2013 IP
  11. Xavier2013

    Xavier2013 Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #11
    Good example. I didn't base my answer on an " if " . That's usually a waste of time and money, two things most people don't have these days. Good work though , thank you. I hope it helps the OP and you are correct.:)
     
    Xavier2013, Feb 21, 2013 IP