gpt4 book ai didi

ruby-on-rails - 我的旧网站是否被正确重定向?

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

大约一年前,我将三个网站(oldsite.com、oldsite.nu、newsite.se)合并为一个,并保留在其中一个域(newsite.se)上。我不确定这是否正确,因为即使在一年之后,我仍然看到来自 Google 的大量旧 url:s 流量。

旧站点重定向代码

重要的编辑说明:我最近意识到名称服务器不再指向我的旧 Rails 应用程序,而是指向我的网络主机上的一个 php 文件夹,其中我有一个带有以下代码的 .htaccess:

RewriteEngine on
RewriteRule ^robots.txt - [L]
RewriteRule ^sitemap.xml - [L]
RewriteRule ^(.*)$ http://www.newsite.se/$1 [R=301,L]

This makes this section below (regarding oldsite.com/oldsite.nu) void: The .com and .nu were built in Ruby on Rails and hosted on Heroku.

The logic to redirect paths from oldsite.com/oldsite.nu were made completely on the newsite.se site. The redirection code on the oldsites is a straightforward redirection with this on the first row in routes.rb on oldsite.com:

  match "/(*path)" => redirect {|params, req| "http://www.newsite.se/#{params[:path]}"},  via: [:get, :post]


我使用这个(瑞典语)工具来验证这个重定向实际上是一个 301 重定向: http://301redirect.se .它确认重定向是 301。

Newsite.se 重定向处理程序

每个旧网站上的内容都与新网站上的相同内容相匹配,很少在同一路径上,例如
oldsite.com/categories/vacation/item/1243

可能导致
newsite.se/product-items/1243

我主要在内部重定向 Controller 中处理这些类型的重定向,该 Controller 捕获并重定向 newsite.se 上的任何流量,例如:
newsite.se/categories/vacation/item/1243 -> newsite.se/product-items/1243

在我的 newsite.se routes.rb 的底部使用它:
match '*not_found_path', :to => 'redirections#not_found_catcher', via: :get, as: :redirect_catcher, :constraints => lambda{|req| req.path !~ /\.(png|gif|jpg|txt|js|css)$/ }

这工作正常。

编辑 20151223:我使用 Newsite.se 处理重定向的原因是因为它包含重定向路径的所有逻辑。 Oldsite.com/.nu 几乎不可能知道这一点。

采取的措施

除了使用 301 重定向之外(据我所知,我愿意)。我还使用谷歌网站管理员工具从我的两个旧网站向我的新网站发出“更改地址的请求”。我再也找不到这方面的任何信息了,但我很确定我已经从 WMT 得到了积极的回应,这已经完成了(但我不是 100% 确定)。

问题提示

我不是 100% 肯定有什么问题,但我看到的迹象让我相信重定向没有正确进行,因此谷歌真正意识到网站没有移动。
  • 在 Google 网站管理员工具和“传入链接”中,顶部链接域是 herokuapp.com,这在术语上表示 oldsite.com。 IE。 301 重定向似乎被解释为链接(而不是重定向)。
  • 我经常在 Google WMT 上获得有关在 newsite.se 上无法访问的 url 的“Not founds/404”(不知道这部分在英文版中叫什么)的新指示。当我检查这些网址的来源时,我经常看到来自例如的链接。 oldsite.nu/oldpath/productitem/1234 - 就像某人(谷歌?)仍然访问了那个旧网址。其中一个重要的部分是,我没有那么多指向旧网站的链接,所以我不希望这些来自仍然提供流量的旧链接。
  • 我的许多旧路径(来自 oldsite.com/oldsite.new)仍然有流量。我通过我的重定向 Controller 找到了这一点,该 Controller 每天处理旧路径上的大量请求。
  • 该网站在 Google SERP 中失去了很多职位,这只是一个微弱的迹象,因为可能有很多原因。

  • 解决问题
  • 我应该如何解决这个问题?
  • WMT 将 301 视为链接是否正常?
  • 有没有比我的 routes.rb-match 行更聪明的方法来处理来自 oldsite.com 的重定向?
  • 最佳答案

    我必须为移动大型电子商务网站的客户做类似的举动,这需要将所有旧流量转移到新网站并将适当的产品重定向到新路径。

    为了使所有内容都转换,因此我们不会丢失 Google 排名,我们必须实现 301 重定向,如您上面提到的。在 WMT 中,他们似乎依赖您来处理此问题,而不是再将其作为受支持的功能。

    联系方式

    You should redirect every URL on your old domain to the corresponding new URL. That is the documented & recommended way of changing your domain according to Google.



    最好的方法是在 Controller 中处理重定向,并有逻辑将其发送到具有 301 的实际页面,并且在登陆新网站后不再进行重定向。

    我建议如下:

    路线.rb (oldsite.com/oldsite.nu)

    匹配请求并将其发送到 Controller 以处理更精细的逻辑和 301。
    match "/(*path)", to: 'redirector#catch_all',  via: [:get, :post]

    重定向 Controller (oldsite.com/oldsite.nu)
    def catch_all
    # Separate the rest of the link into its components
    # I will use the example of the vacation -> product-items you have
    options = params[:path].split('/')
    options.reject! { |e| e.to_s.empty? } # Remove trailing junk if any
    if options[0] == 'categories'
    redirect_to "http://www.newsite.se/product-items/#{options.last}", notice: 'Product Updated! We Have A New Site.', status: 301
    return # the return here is a MUST for more complex if-then and multiple redirect_to's
    elsif options[0] == 'contact'
    redirect_to "http://www.newsite.se/contact-us", notice: 'We moved, Contact us Here.', status: 301
    return
    elsif options.empty? || options.blank?
    redirect_to "http://www.newsite.se/", notice: 'That page no longer exists, Please browse our new site', status: 301
    return
    else
    more_sorting(options)
    end
    end

    private

    def more_sorting(options)
    case options
    when options[2].....
    redirect_to ....., notice: '', status: 301
    return
    when options[3].....
    redirect_to ....., notice: '', status: 301
    return
    when options[4].....
    redirect_to ....., notice: '', status: 301
    return
    end
    end

    为什么要这样:

    这将导致搜索引擎机器人和用户仍然能够抓取和访问每个页面和链接,并被重定向到新网站上与之关联的特定页面。

    此外,它处理此服务器上的 301 重定向,并且不会导致新服务器上的另一个重定向。你可能会因为用户体验和机器人对你试图联合站点的解释而受到惩罚。 (这也很可能会删除对链接 301 的解释)

    如果您需要更复杂的路由,您可以在 RedirectController 中添加(正如我必须做的)私有(private)函数,以更深入地分析我作为最后一个 else 的参数。在如果那么。

    澄清?

    如果您有任何其他问题以及这是否有帮助,请告诉我。

    关于ruby-on-rails - 我的旧网站是否被正确重定向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34255306/

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