Created
October 31, 2012 20:10
-
-
Save dignoe/3989505 to your computer and use it in GitHub Desktop.
Redirect all domains to specified domain in Rails 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MyApp::Application.routes.draw do | |
if Rails.env.production? | |
constraints(:host => /^(?!www\.my-domain\.com)/) do | |
match "(*path)" => redirect { |params, request| URI.parse(request.url).tap { |x| x.host = "www.my-domain.com" }.to_s} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use this to redirect non www URLs to your domain. In addition, it redirects any domain that is not the one you specified (i.e. 192.168.0.1, ec-192-168-0-1.amazon-aws.com, etc.).