How to Set Redirection Using Routes.rb

Ruby On Rails icon
Ruby On Rails provide many ways to set up redirection. It can be done through the function on controller. However, I found that , sometimes setting up redirection through function on controller can be a bit complicated. And unfortunately, at that time I haven't realized that setting up redirection can be done on routes.rb file too. How to do that ?

Setting up redirection on routes.rb is very simple if you're familiar with routing configuration in Ruby On Rails. For example, you want to redirect /about-me to /contact-me.html. Assuming you have set up the controller and function for both of them, you only need to add the following codes to your routes.rb file.
match "/about-me" => redirect("/contact-me")

It's very simple. It will also safe some line of codes on your controller. But, is it possible to redirect a dynamic page such /posts/1 to /pages/1 ? Yes it is possible. You only need to change the above codes to such:
match "/posts/:id" => redirect("/pages/%{id}")

Based on the documentation, this redirection is 301. That means a permanent redirection.