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

大约一年前,我将三个网站(oldsite.com,oldsite.nu,newsite.se)合并成一个,我保留在其中一个域名(newsite.se)上.我不知道这是否已经正确,因为我仍然看到很多来自Google的旧网址流量,甚至一年以后.

站点重定向代码

重要的编辑笔记:我最近意识到,名称服务器不再指向我的旧轨道应用程序,而是指向我的网络主机上的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:

06001

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

Newsite.se重定向处理程序

每个旧网站上的内容与新的网站上的内容相同,很少在相同的路径上匹配.

oldsite.com/categories/vacation/item/1243

可能导致

newsite.se/product-items/1243

我处理这些类型的重定向,主要是在一个内部重定向控制器中,捕获并重定向在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之外重定向(据我所知,我做).我也使用Google网站管理员工具从我的旧两个网站做出“请求更改地址”到我的新网站.我找不到任何这方面的信息,但我确信我得到了一个积极的回应,WMT这个hade已经完成(但我不是100%确定).

问题指示

我不是100%肯定有什么问题,但是我看到有迹象表明我认为重定向不正确,Google真的意识到网站没有被移动.

>在Google网站管理员工具和“传入链接”中,顶级链接域是herokuapp.com,这意味着oldsite.com.即301重定向似乎被解释为链接(而不是重定向).
>我经常在Google WMT上获得关于“未找到/ 404”(不知道这个部分在英文版本中调用什么)的新迹象,因为在newsite.se无法达到的url.当我检查这些URL的来源时,我经常看到例如oldsite.nu/oldpath/productitem/1234 – 像某人(Google?)仍然访问过旧的网址.其中一个重要的部分是我没有很多链接到旧站点,所以我不期望这些来自旧的链接仍然供应流量.
>我仍然得到许多旧路径的流量(来自oldsite.com/oldsite.new).我通过我的重定向控制器找到这一点,它每天在旧路径上处理大量的请求.
>该网站在Google SERP中失去了很多职位,这只是一个弱势,尽管可能有很多原因.

解决问题

>我应该如何解决这个问题呢?
> WMT将301作为链接考虑是否正常?
>有没有更好的方式处理从oldsite.com的重定向比我的routes.rb-match行?

解决方法

我不得不为一个客户移动一个大型电子商务网站,需要将所有旧流量转换到新网站,并将适当的产品重定向到新的路径.

为了让一切都过渡,所以我们没有丢失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.

最好的方法是处理控制器中的重定向,并将逻辑发送到具有301的实际页面,一旦登陆新网站就不再有重定向.

我会建议如下:

routes.rb(oldsite.com/oldsite.nu)

匹配请求并将其发送到控制器以处理更精细的逻辑和301.

match "/(*path)",to: 'redirector#catch_all',via: [:get,:post]

RedirectorController(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 .....,status: 301
        return
    when options[4].....
        redirect_to .....,status: 301
        return
    end
end

为什么这样做:

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

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

如果您需要更复杂的路由,您可以添加(如我必须)在RedirectController中的私有函数,以便更深入地分析我在if中的最后一个参数.

澄清?

如果您有任何其他问题,如果这有帮助,请告诉我们.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...