问题描述
所以目前,由于我的托管服务提供商(Heroku)的限制,我是从裸体域手动指导的。一切都很好。问题是,如果用户访问mydomain.com/route,将重新发送回www.mydomain.com而不使用/ route。我如何去重新添加路线,但仍然重定向到www。 ?
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
编辑
我从我的ApplicationController中删除了我的代码,并选择使用,由hurikhan77提出,解决了我的问题。
I removed my code above from my ApplicationController, and opted for using the refraction gem as suggested by hurikhan77, which solved my problem.
这里是refraction_rules.rb我使用的。 / p>
Here is refraction_rules.rb I used.
Refraction.configure do |req|
if req.host == "domain.com"
req.permanent! :host => "www.domain.com"
end
end
推荐答案
我建议您使用折射宝石:
I suggest using the refraction gem for this: http://rubygems.org/gems/refraction
这篇关于Rails手动从裸域重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!