All*_* L. 27 subdomain redirect ruby-on-rails
使用Morph Labs的Appspace部署站点意味着没有自动方式将"myapp.com"重定向到"www.myapp.com"(并且无法访问.htacess).
有这样的轨道方式吗?我需要一个像subdomain-fu这样的插件吗?
更具体地说,我正在尝试做类似的事情:
基本上,我总是希望每个请求都附加'www'子域名(因为SSL证书的具体名称是'www.myapp.com').
car*_*son 30
也许这样的事情可以解决问题:
class ApplicationController < ActionController::Base
before_filter :check_uri
def check_uri
redirect_to request.protocol + "www." + request.host_with_port + request.request_uri if !/^www/.match(request.host)
end
end
Run Code Online (Sandbox Code Playgroud)
小智 9
卡森的回答很有效.
这是代码走另一条路(www - >没有www)
before_filter :check_uri
def check_uri
if /^www/.match(request.host)
redirect_to request.protocol + request.host_with_port[4..-1] + request.request_uri
end
end
Run Code Online (Sandbox Code Playgroud)
我不得不改变Carson的答案,让它在Rails 3中运行.我用request.fullpath替换了request.uri:
class ApplicationController < ActionController::Base
protect_from_forgery
Rails.env.production? do
before_filter :check_url
end
def check_url
redirect_to request.protocol + "www." + request.host_with_port + request.fullpath if !/^www/.match(request.host)
end
end
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7335 次 |
最近记录: |