1

I would like to redirect all requests, that coming to www.website.com/whatever to the variant without www. How to do this in Rails & what is the best way to do that?

user984621
  • 46,344
  • 73
  • 224
  • 412

3 Answers3

4

There are two options for this. If you want to do it within rails the following gem might be useful

https://github.com/iSabanin/www_ditcher

However, such tasks are generally configured from the app server. Please look at this question previously posted on stack overflow

301 redirect in Passenger (Ruby on Rails) from root domain to www sub domain?

It does the complement of what you seek to do, however it should get you on track. Thanks!

Community
  • 1
  • 1
sohaibbbhatti
  • 2,672
  • 22
  • 21
3

I think it's best to keep the logic for that completely our of your Rails app and rather take care of it in the server configuration.

0

gem 'rack-www' works nicely for this.

https://github.com/stjhimy/rack-www

adarsh
  • 396
  • 3
  • 12