How to redirect a URL with GET variables in routes.rb without Rails stripping out the variable first?
- by Michael Hopkins
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?