It is a simple issue, but I can\'t seem to find an answer doing some quick googling.
What\'s the Ruby on Rails way of doing this 301 direct (http://x.com/abc > http:
There is a better Rails 3 way - put this in your routes.rb
file:
constraints(:host => "example.com") do
# Won't match root path without brackets around "*x". (using Rails 3.0.3)
match "(*x)" => redirect { |params, request|
URI.parse(request.url).tap { |x| x.host = "www.example.com" }.to_s
}
end
Update
Here is how to make it domain agnostic:
constraints(subdomain: '') do
match "(*x)" => redirect do |params, request|
URI.parse(request.url).tap { |x| x.host = "www.#{x.host}" }.to_s
end
end