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

前端 未结 9 2124
北荒
北荒 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 19:57

    In Rails 3

    #config/routes.rb
    Example::Application.routes.draw do
      constraints(:host => "www.example.net") do
        match "(*x)" => redirect { |params, request|
          URI.parse(request.url).tap { |x| x.host = "example.net" }.to_s
        }
      end
      # .... 
      # .. more routes ..
      # ....
    end
    

提交回复
热议问题