URLs ending in .html

This is just a personal preference of mine, but I like to have URLs end in .html. Fortunately rails makes this easy:

In your routes file:


map.connect ':controller/:action/:id.html', :format => 'html'

For your other custom routes you will need to also add :format => ‘html’ and the .html at the end of the route line like above.

Update

Another (better?) way to achieve nice URLs in rails, with .html suffixes is to add the following to your ApplicationController:


  def default_url_options(options)
    { :format => 'html' }
  end

This means your routing line is much cleaner. In fact it’s the default!


  map.connect ':controller/:action/:id.:format'