50 Experience
0 Lessons Completed
0 Questions Solved


Posted in How to redirect batch of urls from routes.rb

I have an issue here and struggling with it for hours.
For SEO purpose, I have to redirect (301) something like 200 urls for now, maybe more later, maybe less.
I want to have easy access to it. So I thought about having a dedicated file containing all url I need to redirect.
Something like

# config/seo_redirection_table.yml
- old_path: '/old/path/1'
   new_path: '/new_path_1'
   status: 301 
- old_path: '/old/path/2'
   new_path: '/new_path_2'
   status: 301 

And then in my routes.rb mapping this file at the very top.
Is it a good practice ? What do you think ? And how can I handle this logic in my routes.rb.

logo Created with Sketch.

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

© 2022 GoRails, LLC. All rights reserved.