【发布时间】:2016-06-16 15:20:08
【问题描述】:
在 nginx 配置中我添加了
server_name *.example.com example.com;
如果我只写
server_name www.example.com example.com;
nginx m.example.com 正在重定向到 nginx 配置中配置的第一个网站。
在第一行中,无论使用什么子域,我的网站都会在 rails 上显示相同的结果:m.example.com/hello 或 www.example.com/hello 等。没关系,但应该重定向到 www。
所以我需要重定向所有其他子域 => m.example.com/hello to www.example.com/hello 因为 SEO。如何从routes.rb 进行这种重定向?
现在我只使用规则从无子域example.com/* to www.example.com/*重定向
constraints subdomain: false do
get ':any', to: redirect(subdomain: 'www', path: '/%{any}'), any: /.*/
end
【问题讨论】:
标签: ruby-on-rails redirect nginx