将www url重定向到rails中的非www url

问题描述 投票:0回答:1

我可以从base urlwww to non www重定向我的网站的nginx configuration,但问题是我发送的电子邮件中的网址是www。

www.xyz.com -> xyz.com

成功重定向,但当我尝试运行网址时

www.xyz.com/pqr

它没有被重定向。

我正在使用rails 5.0.7 and ruby 2.5.1

ruby-on-rails ruby nginx nginx-location nginx-config
1个回答
0
投票

您的nginx重定向配置中必定存在一些问题,请尝试:

server {
  server_name  www.example.com;
  rewrite ^(.*) https://example.com$1 permanent;
}

关键是保持$1中url的路径部分

© www.soinside.com 2019 - 2024. All rights reserved.