1

I have an idea to move site from PHP (Joomla + pure php) to Ruby on Rails (Refinery CMS). Old site has links with .html and .php extensions. Is there a way to keep old urls the same (I don't want to loose Google PageRank)? I tried to use config.use_custom_slugs = true config with Refenery, but it drop '.' from url. (store.php becomes storephp, also FAQ.html becomes faqhtml ... etc ) Any help appreciated! Thanks.

In Rails I can do it next way

  #Application Controller
  def unknown_path
    #it works for all urls, here I can load page with needed slug
    render :text => "#{request.fullpath}"
  end

 #routes.rb
  match "*a", :to => "application#unknown_path" #in the end

And it will make any url working. So I could use custom slug if it exist or raise 404

But CMS dosn't allow to create really custom slugs

Why not 301

Trying to explain: you get an external link coming to Page 1, then your Page 1 links internally to Page 2. Link to page 1 gets 1000 amount of page rank from the link. Link to page 2 gets 900 Therefore a link to 301 gets 1000 and the page that the 301 points to gets 900. So: 900 is better than it disappearing altogether, but I'm trying avoiding creating this situation. That how it works.

Fivell
  • 11,829
  • 3
  • 61
  • 99
  • Looking at the debug logs, it looks like when I save a period is stripped out before the SQL update, but I've dug through Refinery's source, and couldn't find any reference to that stripping out in a before_save or anything. It may be caused by friendly_id gem stripping it out behind the scenes? – creativereason Jul 10 '13 at 01:42
  • One other thing that it sounds like you have already decided against, but seems just as SEO friendly without sacrificing much ranking... Have you considered doing a 301 redirect via .htaccess file to the new (more SEO friendly) urls from refinery? – creativereason Jul 10 '13 at 01:48
  • @creativereason, thanks for comments. I suggested 301 redirects but one of the main requirements is to keep old urls =( – Fivell Jul 10 '13 at 07:52
  • maybe you do know any other rails CMS, which supports it out of the box? – Fivell Jul 10 '13 at 07:55

2 Answers2

0

As per my answer on Refinery's issue tracker, where this was also asked, do you have to do this in Rails? What about rewriting the request before it even gets to Rails using proxy software such as nginx with HttpRewriteModule?

parndt
  • 1,873
  • 11
  • 13
0

I ran into a similar issue when moving from wordpress to Comfortable Mexican Sofa ( another Rails CMS engine).

I ended up doing this in my routes.rb ( here is a sample of one of the redirects ( I don't have a lot - total of 15 redirects like that), which is generic Rails solution that can be used by RefineryCMS as well I think.

get '/2009/01/28/if-programming-languages-were-cars/', to: redirect('/blog/2009/01/if-programming-languages-were-cars-translated-into-russian')

This actually generates a proper redirect like so ( impossible to see in the browser, but if you curl you'll see this:

curl http://gorbikoff.com/2009/01/28/if-programming-languages-were-cars/


<html>
  <body>
    You are being <a href="http://gorbikoff.com/blog/2009/01/if-programming-languages-were-cars-translated-into-russian">redirected</a>.
  </body>
</html>

And if we check headers - we see a proper 301 response:

curl -I http://gorbikoff.com/2009/01/28/if-programming-languages-were-cars/

returns

HTTP/1.1 301 Moved Permanently
Content-Type: text/html
Content-Length: 158
Connection: keep-alive
Status: 301 Moved Permanently
Location: http://gorbikoff.com/blog/2009/01/if-programming-languages-were-cars-translated-into-russian
X-UA-Compatible: IE=Edge,chrome=1
Cache-Control: no-cache
X-Request-Id: 9ec0d0b29e94dcc26433c3aad034eab1
X-Runtime: 0.002247
Date: Wed, 10 Jul 2013 15:11:22 GMT
X-Rack-Cache: miss
X-Powered-By: Phusion Passenger 4.0.5
Server: nginx/1.4.1 + Phusion Passenger 4.0.5   

Specific to your case

So that's the general approach. However for what you are trying to do ( redirect all urls that end in .php like yourdomain.com/store.php to yourdomain.com/store) you should be able to do something like this. This assumes that you'll (map your new structure exactly, otherwise you may need to create a bunch of custom redirects like I mentioned in the beginning or do some Regex voodoo) :

NON-Redirect Solution

Don't redirect user, just render new page at the same address (it's a twist on solution you put in your question):

This is the only way that's more or less robust, if you don't want to do a redirect.

# routes.rb
# You don't need to match for .html - as they will be handled automatically by rails.
match '/*\.php', to: "application#php_path"

# application_controller.rb  
# This doesn't have to be application controller, 
# you may do this in your home_controller if you wish.
def php_path
  require 'open-uri'
  file = open "http://#{request.host_with_port}#{request.fullpath.gsub!(/(.php)/,'')}"
  render :inline => file.read
end

Redirect Solution: According to Google 301 is the preferred way https://support.google.com/webmasters/answer/93633?hl=en .

match '/*\.php', to: redirect {|params, request|
  "http://#{request.host_with_port}#{request.fullpath.gsub(/(.php)/,'')}"
}

This will provide a Response Header Status Code 200. As far as the world is concerned you are serving PHP through passenger ( run curl -I against my site using this sample urls - these are just arbitrary params to illustrate my point)

curl -I http://gorbikoff.com/about?name=nick
curl -I http://gorbikoff.com/about.php?name=nick

You may need to fidget with this based on your specifics ( https vs http, etc, and maybe some virtual routes need to be address separately. Also remember about precedence in the route.rb ) but I think this might work for you.

EDIT I just realized that this solution works out of the box in Comfortable Mexican Sofa ( it just ignores format ( .php is treated same way .html would be treated). However I tried my solutions in non-cms based rails 3 project I have ( it's not public) and my solution still holds with slight change - I just fixed it (sorry for the confusion).

I suggest also to check official guide at (I'm assuming you are on Rails 3.2.13 since RefinderyCMS doesn't support Rails 4 officially yet)

http://guides.rubyonrails.org/v3.2.13/routing.html#redirection

And check out Rails API

http://api.rubyonrails.org/v3.2.13/classes/ActionDispatch/Routing/Redirection.html#method-i-redirect

Hope that helps

Community
  • 1
  • 1
konung
  • 6,908
  • 6
  • 54
  • 79
  • Thanks for response, but I won't to use 301 redirect because of loosing Google PAge rank for each such page. – Fivell Jul 10 '13 at 15:33
  • Give me a few mins, I think I came up with a solution that might work for you – konung Jul 10 '13 at 16:08
  • @Fivell Check out my updated answer, let me know if that's what you were looking for. – konung Jul 10 '13 at 16:20
  • @Fivell I just updated my answer again - I remember reading that 301 was preferable. I was looking for this link (https://support.google.com/webmasters/answer/93633?hl=en) – konung Jul 10 '13 at 16:30