Ruby on Rails and standard mod_rewrite

965 Views Asked by At

I've got an old application written in PHP and now I am replacing it by new RoR app. The old application has links like "this-is-seo-title,n123.html". In htaccess there is a rule which is translating those links to news.php?id=123.

Now when I setup RoR app, links are in "RoR way" (:controller/:action/:id). It's cool and nice, but in Google I've got about 50k indexed subpages. I don't want get this indexed subpages broken so now here is a question:

Can I create new rules inside htaccess file which will be translating "this-is-seo-title,n123.html" links to /news/123 ?

I didn't deploy app yet and I don't have access to environment with passenger module, so I can't test it myself.

1

There are 1 best solutions below

2
On

I don't think it's necessary to use htaccess. If you are going rails, then do it with the rails helpers. I think this should work in your routes.rb:

match 'this-is-seo-title,n:id.html' => 'news#show'

That route will invoke the NewsController and the show action with 123 as an :id parameter. Was that what you where looking for?

Edit:

For Rails 2

map.connect 'this-is-seo-title,n:id.html', :controller => 'news', :action => 'show'

At least I think that will work in Rails 2. I don't have any environment up and running atm to test with. Let me know if it doesn't work.