Redirect to www for heroku with SSL

Neeraj Singh

By Neeraj Singh

on October 12, 2012

If you are using heroku and if you have enabled https then site must be redirected to use www . It means all Rails applications should ensure that "no-www" urls are redirected to "www".

In Rails3 it is pretty easy to do. Here is how it can be done.

1Bigbinary::Application.routes.draw do
2
3  constraints(:host => /^bigbinary.com/) do
4    root :to => redirect("http://www.bigbinary.com")
5    match '/*path', :to => redirect {|params| "http://www.bigbinary.com/#{params[:path]}"}
6  end
7
8end

Stay up to date with our blogs. Sign up for our newsletter.

We write about Ruby on Rails, ReactJS, React Native, remote work,open source, engineering & design.