How do I redirect without www using Rails 3 / Rack?

前端 未结 9 2131
北荒
北荒 2020-12-12 19:36

I understand there are a lot of questions that answer this. I\'m familiar with .htaccess and nginx.conf methods, but I do not have access to such t

9条回答
  •  忘掉有多难
    2020-12-12 20:05

    A one-line version of Duke's solution. Just add to the top of routes.rb

    match '(*any)' => redirect { |p, req| req.url.sub('www.', '') }, :constraints => { :host => /^www\./ }
    

提交回复
热议问题