gpt4 book ai didi

ruby-on-rails - 如何在不丢失 Google 索引的情况下正确地将网站从 http 重定向到 https

转载 作者:行者123 更新时间:2023-12-04 06:53:02 25 4
gpt4 key购买 nike

我最近为旧的 Rails 2.3.1 网站添加了 SSL 支持。我有以下代码可以从 http 重定向到 https:

应用 Controller :

  before_filter :need_ssl

protected


def need_ssl
if RAILS_ENV=="production"
redirect_to "https://#{request.host}#{request.request_uri}" unless request.ssl?
end
end

但是我收到了一条来自谷歌的消息:
Approximately 80% of your HTTP pages that were indexed before migration can no longer be found in either your HTTP or HTTPS site

我查看并发现 572 由于重定向而被排除在索引之外。

然后如何添加正确的重定向代码,以免丢失索引?

最佳答案

这是我通常将我的网站迁移到 https 所做的工作.

全部重定向 http流量到https301 redirect在我的 nginx配置

server {
listen 80;
server_name myawesomewebsite.com;
return 301 https://myawesomewebsite.com$request_uri;
}

启用 force_sslconfig/application.rb
config.force_ssl = true

编辑:谢谢大家投票给我的答案。但也请检查@agilejoshua 的回答,因为他提供了很多有用的信息。

关于ruby-on-rails - 如何在不丢失 Google 索引的情况下正确地将网站从 http 重定向到 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52465191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com