I want to redirect all incoming requests to my root domain, and found the code below at devcenter.heroku.com/articles/custom-domains.
This redirect works fine, except that . For example, http://judge.me/faq works but http://www.judge.me/faq redirects to judge.me homepage.
I know I have to add a parameter to this function, but can not find the name of the params key which stores the last section of the URL. Can someone help me or refer me to the right place?
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :ensure_domain
APP_DOMAIN = 'judge.me'
def ensure_domain
if request.env['HTTP_HOST'] != APP_DOMAIN
# HTTP 301 is a "permanent" redirect
redirect_to "http://#{APP_DOMAIN}", :status => 301
end
end
end