Rails manually redirecting from naked domain
dns, heroku, ruby-on-rails
Solution
I suggest using the refraction gem for this: http://rubygems.org/gems/refraction
Problem
So currently I am manually directing from a naked domain due to restrictions with my hosting provider (Heroku). Everything works just fine. The problem is that if a users visits mydomain.com/route, a redirect will be issued back to www.mydomain.com without the /route. How would I go about re-appending the route, but still redirecting to www. ? ``` class ApplicationController < ActionController::Base protect_from_forgery before_filter :ensure_domain APP_DOMAIN = 'www.domain.com' def index end def ensure_domain if Rails.env.production? if request.env['HTTP_HOST'] != APP_DOMAIN redirect_to "http://#{APP_DOMAIN}", :status => 301 end end end end ``` EDIT I removed my code above from my ApplicationController, and opted for using the refraction gem as suggested by hurikhan77, which solved my problem. Here is refraction_rules.rb I used. ``` Refraction.configure do |req| if req.host == "domain.com" req.permanent! :host => "www.domain.com" end end ```