0

I've never touched Ruby or Rails and I have a relatively simple task to execute. I have an old site and a new site my company is launching. I want to map the URLs from the old site, so if anyone visits them, there is a 301 redirect to the URLs on the new site. i.e.

oldsite.com/ --> newsite.com/
oldsite.com/people --> newsite.com/team
oldsite.com/companies --> newsite.com/companies

and if and if anyone enters a random / old URL they are redirected to the new site homepage. e.g.

oldsite.com/anyoldurl --> newsite.com/

How would I make these changes? This is what the routes.rb file currently looks like:

CompanyName::Application.routes.draw do

  match 'admin/' => 'admin#authenticate', :as => :admin

  match 'logout/' => 'admin#logout'

  resources :people
  resources :companies

  match 'jobs/' => "companies#jobs", :as => :jobs
  match 'platformpm' => 'welcome#platformpm'
  match 'analyst' => 'welcome#analyst'

  #Experimental Jobs Page
  match 'jobs-experimental/' => "companies#jobs_experimental", :as => :jobs_experimental
  match 'jobs-experimental/renew' => "companies#jobs_experimental_renew", :as => :jobs_experimental_renew

  match 'giftguide' => "welcome#gift_guide"

  get 'positions' => redirect('/jobs/')
  get 'positions/:id' => redirect('/jobs/')
  get 'peoples' => redirect('/people')


  root :to => "welcome#index"
Suraj Kapoor
  • 1,615
  • 4
  • 22
  • 34
  • You cannot reroute to another domain using routes.rb. I think you should talk to operations and let them add a DNS-entry, or something like that. – Andreas Gnyp Sep 26 '14 at 19:20
  • There must be another way, we want to avoid DNS settings. Apparently .htaccess is incompatible with Heroku. – Suraj Kapoor Sep 26 '14 at 19:40
  • Why avoid changing the DNS? It's the fastest and easiest way to do this. It won't waste a CPU or network traffic. If you must do it in code, then write a simple redirector using something like [Sinatra](http://www.sinatrarb.com/), which will easily handle that sort of traffic without all the garbage of an unused Rails stack. – the Tin Man Sep 26 '14 at 19:45
  • @theTinMan agreed, I think make a lightweight app to redirect is the best solution. Re the DNS change - http://stackoverflow.com/questions/681869/301-redirect-vs-dns-change-is-it-ever-safe-to-kill-a-301-redirect-and-update-th – Suraj Kapoor Sep 26 '14 at 21:05

0 Answers0