mod_rewrite ignore query string.

Discussion in 'Apache' started by blackbug, Oct 9, 2005.

  1. #1
    Hi,

    I've got a lot of spidered and indexed content from an old CMS that starts

    index2.php?blah=blah&blah=blah&blah=blah

    I want to send anything hitting this to the front page, without the query string. I'm crap at mod_rewrite, so I need a hand, currently, I've got the line:

    RewriteRule ^(index2.php?.*)$ / [R=301,L]

    and I've tried

    RewriteRule ^(index2.php.*)$ / [R=301,L]

    Any ideas, these just redirect to /?blah=blah&blah=blah&blah=blah but I just want it to go to /

    Cheers,

    Chris
     
    blackbug, Oct 9, 2005 IP
  2. johnt

    johnt Peon

    Messages:
    178
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think that you can strip an existing query string from a redirect by using a ? at the end, i.e

    RewriteCond %{REQUEST_URI} ^index2.php
    RewriteRule ^(.*)$ /? [R=301,L]

    cheers

    johnt
     
    johnt, Oct 9, 2005 IP
    blackbug likes this.
  3. blackbug

    blackbug Peon

    Messages:
    1,002
    Likes Received:
    89
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks, but that didn't seem to work... or indeed match anything. Guess I should read the mod_rewrite docs one day :)
     
    blackbug, Oct 9, 2005 IP
  4. johnt

    johnt Peon

    Messages:
    178
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Sorry, the RewriteCond should have a / in it

    RewriteCond %{REQUEST_URI} ^/index2.php
    RewriteRule ^(.*)$ /? [R=301,L]
     
    johnt, Oct 9, 2005 IP
  5. blackbug

    blackbug Peon

    Messages:
    1,002
    Likes Received:
    89
    Best Answers:
    0
    Trophy Points:
    0
    #5
    muchas gracias!

    Excellent. Thanks.
     
    blackbug, Oct 9, 2005 IP