Redirect from .com to .org

For a Rails application hosted on Heroku, we are using Zerigo DNS Add-on to point a custom domain (say mydomain.org) to point to the Heroku app. We have SSL certificate registered for mydomain.org

Now, we would want mydomain.com to redirect to mydomain.org. We tried implementing redirect rules at the controller/rack level. Doesn't work. The browser URL still points to .com instead of .org

Has anybody faced the same problem with an Heroku app!!?


I've used the following technique to redirect from "example.com" to "www.example.com" (as described here, http://docs.heroku.com/custom-domains). This might work in your case to redirect from .com to .org.

In app/controllers/application_controller.rb :

class ApplicationController < ActionController::Base
  protect_from_forgery

  before_filter :ensure_domain

  protected

  def ensure_domain
    if request.env['HTTP_HOST'] != 'www.example.com' && Rails.env.production?
      redirect_to "http://www.example.com", :status => 301
    end  
  end

end

In your case, you would point the DNS records for your .com and .org domains to your app running on Heroku. Your app would check the HTTP_HOST to see if it specifies your .org URL. If it does not, then it would redirect to your .org URL.

链接地址: http://www.djcxy.com/p/60098.html

上一篇: Rails 3 Heroku上的SSL

下一篇: 从.com重定向到.org