Can I do simple redirect in htaccess if ? is in URL

Discussion in 'Apache' started by Darden12, Oct 11, 2008.

  1. #1
    I know how to redirect static pages in the htaccess page as follows:

    Redirect Permanent /old_address.html /new_address.html

    Is there some way to make this work with a question mark in a URL:

    Redirect Permanent /old_address.html?ID=5 /newaddress.html

    The first redirect above works for me, but the second doesn't. Any ideas what I'm doing wrong.

    Thanks
     
    Darden12, Oct 11, 2008 IP
  2. seismic2

    seismic2 Peon

    Messages:
    27
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    RewriteRule (I'm not sure about the Redirect directive), doesn't take query strings(the part after the question mark) into account. Your only bet is to use RewriteCond to match the query string.

    RewriteCond %{QUERY_STRING} ^ID=5$
    RewriteRule ^old_address\.html /newaddress.html [R=301,L]
    Code (markup):
     
    seismic2, Oct 11, 2008 IP
  3. Akela

    Akela Member

    Messages:
    12
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    40
    #3
    I just wanted to thank seismic2. I have looked for a way to redirect from one phpBB thread to another the whole morning today, and your answer is the only one that worked for me. Thank you!
     
    Akela, May 4, 2010 IP