因此,目前我手動從裸域導致由於與我的託管服務提供商(Heroku)的限制。一切正常。問題是,如果用戶訪問mydomain.com/route,重定向將發送回www.mydomain.com而不使用/ route。我將如何去重新添加路線,但仍然重定向到www。 ?Rails手動從裸域重定向
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
我刪除我上面的代碼從我的ApplicationController,並選擇了使用refraction gem通過hurikhan77的建議,這解決了問題。
這是我使用的refraction_rules.rb。
Refraction.configure do |req|
if req.host == "domain.com"
req.permanent! :host => "www.domain.com"
end
end
嘿,這很好。感謝它的工作。 – prettymuchbryce
不客氣。 – hurikhan77
此外,對於任何人都磕磕絆絆,我發佈了上述正確的折射規則。 – prettymuchbryce