How to redirect a URL with GET variables in routes.rb without Rails stripping out the variable first?
        Posted  
        
            by 
                Michael Hopkins
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Michael Hopkins
        
        
        
        Published on 2012-07-03T22:25:03Z
        Indexed on 
            2012/07/05
            21:15 UTC
        
        
        Read the original article
        Hit count: 331
        
I am building a website in Rails to replace an existing website. In routes.rb I am trying to redirect some of the old URLs to their new equivalents (some of the URL slugs are changing so a dynamic solution is not possible.)
My routes.rb looks like this:
  match "/index.php?page=contact-us" => redirect("/contact-us")
  match "/index.php?page=about-us" => redirect("/about-us")
  match "/index.php?page=committees" => redirect("/teams")
When I visit /index.php?page=contact-us I am not redirected to /contact-us. I have determined this is because Rails is removing the get variables and only trying to match /index.php. For example, If I pass /index.php?page=contact-us into the below routes I will be redirected to /foobar:
  match "/index.php?page=contact-us" => redirect("/contact-us")
  match "/index.php?page=about-us" => redirect("/about-us")
  match "/index.php?page=committees" => redirect("/teams")
  match "/index.php" => redirect("/foobar")
How can I keep the GET variables in the string and redirect the old URLs the way I'd like? Does Rails have an intended mechanism for this?
© Stack Overflow or respective owner