开发者

rails 3: https redirect, but only for one specific domain name (or several)

My app has user-facing and public-facing pages which are accessd via different subdomains user.example.com and public.example.com

I have a ssl cert for user.example.com and it all works fine when the user comes in via htt开发者_如何学运维ps.

And I know how to redirect to https for ANY domain used by my app, but not for ONE specific domain.

However, if someone comes in on http://user.example.com I'd like to redirect to https://user.example.com without doing nay special redirect for other subdomains (or domains) they might come in on.

Is there a way in rails to redirect to https all requests that come on one specific subdomain?


The best place to do this is in your web server (e.g. Apache, nginx, etc.) configuration. If you don't have access to that, then write a before_filter in ApplicationController that compares against request.host and request.ssl? e.g.:

def redirect_user_subdomain_to_https
  if 'user.example.com' == request.host && !request.ssl?
    redirect_to request.url.gsub(/^http/, 'https')
    return false
  end
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜