重定向“myapp.com”到“www.myapp.com”在铁轨,而无需使用htaccess的?铁轨、重定向、myapp、com

2023-09-02 00:31:09 作者:24.十足痞子味

使用Morph实验室AppSpace后部署一个站点意味着没有自动化的方式来重定向myapp.com'到'www.myapp.com(和.htacess无法访问)。

Using Morph Labs' Appspace to deploy a site means no automated way to redirect 'myapp.com' to 'www.myapp.com' (and no access to .htacess).

有一个在轨的方式来做到这一点?我需要像子域福插件?

Is there an in-rails way to do this? Would I need a plugin like subdomain-fu?

更具体地说,我试图做这样的事情:

More specifically, I'm trying to do something like:

在myapp.com'=>​​'www.myapp.com 在myapp.com/session/new'=>'www.myapp.com/session/new

基本上,我总是想ppended在每次请求的WWW的子域$ P $(因为SSL证书专门有一个共同的名字www.myapp.com)。

Basically, I always want the 'www' subdomain prepended on every request (because the SSL cert specifically has a common name of 'www.myapp.com').

推荐答案

也许这样的事情会做的伎俩:

Maybe something like this would do the trick:

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