I am remaking an old php website into RubyOnRails (3.0.3). The existing website (written in php) has been online for some years now and gained a lot of links and is well positioned in Google.
Now, since I am releasing it in Rails on the same domain I want the old files to be 301 redirected to the corresponding file in the new version. What would be the best way?
These are the circumstances:
- I am building the new website on the same domain where I am replacing the php-version
- There is no logic in how the files have been renamed. For example http://www.domain.com/cat/home/page/helloworld.php might have its corresponding place at http://www.domain.com/stuff/hello-world-in-rails and some files have been removed etc.
- Thus, I would like to specify in a table, or similar, where one column is the old path and the other column is the new path. When someone tries to access http://www.domain.com/cat/home/page/helloworld.php they will be 301:d to http://www.domain.com/stuff/hello-world-in-rails
When I have made php-sites into WordPress I have solved this by adding a redirect code in each php file pointing to the new path (in WordPress). Since my Rails-installation doesn’t support php-files, this is not possible however.
I assume mod_rewrite is my weapon of choice, but how should I go at it?
You can manage all the redirections in the routes file. Here the documentation f the routes, espacially the redirct method will be interresting for you!
http://guides.rubyonrails.org/routing.html#redirection