Skip to content

Instantly share code, notes, and snippets.

@stevenharman
Created August 28, 2012 16:24
Show Gist options
  • Save stevenharman/3499918 to your computer and use it in GitHub Desktop.
Save stevenharman/3499918 to your computer and use it in GitHub Desktop.
Redirect from www.* to your apex domain. Or from your apex domain to a www. subdomain.
Brewhouse::Application.routes.draw do
constraints(host: /^(?!www\.)/i) do
match '(*any)' => redirect { |params, request|
URI.parse(request.url).tap { |uri| uri.host = "www.#{uri.host}" }.to_s
}
end
resource :drink_up, only: [:show]
root :to => redirect('/drink_up')
end
Brewhouse::Application.routes.draw do
constraints(host: /^www\./i) do
match '(*any)' => redirect { |params, request|
URI.parse(request.url).tap { |uri| uri.host.sub!(/^www\./i, '') }.to_s
}
end
resource :drink_up, only: [:show]
root :to => redirect('/drink_up')
end
@elquimista
Copy link

via: :all should be appended to match since Rails 4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment