Skip to content

Instantly share code, notes, and snippets.

@mitio
Created September 19, 2011 18:20
Show Gist options
  • Save mitio/1227170 to your computer and use it in GitHub Desktop.
Save mitio/1227170 to your computer and use it in GitHub Desktop.
Permanent redirects in routes.rb, while preserving query-string args
# take care of old, legacy routes
redirect_with_query_string = lambda do |path|
redirect do |params, req|
path << "?#{req.query_string}" unless req.query_string.blank?
path
end
end
# example usage
match 'legacy_root_path' => redirect_with_query_string.call('/')
match 'studios/props' => redirect_with_query_string.call('/studios/gear')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment