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]
我使用这个(瑞典)工具来验证这个重定向实际上是否重定向到: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排名,所以我们不得不实施301重定向,如上所述.在WMT中,他们似乎依靠你来处理这个问题,而不是把它当作一个支持的函数. 途径
最好的方法是处理控制器中的重定向,并将逻辑发送到具有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中的最后一个参数. 澄清? 如果您有任何其他问题,如果这有帮助,请告诉我们. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |