Redirect non-www requests to www URLs in Ruby on Rails

前端 未结 7 2012
無奈伤痛
無奈伤痛 2020-12-01 09:52

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:

7条回答
  •  孤街浪徒
    2020-12-01 10:40

    An alternative solution might be to use the rack-canonical-host gem, which has a lot of additional flexibility. Adding a line to config.ru:

    use Rack::CanonicalHost, 'www.example.com', if: 'example.com'
    

    will redirect to www.example.com only if the host matches example.com. Lots of other examples in the github README.

提交回复
热议问题