Reputation: 23395
I'm working on a project where the client's SEO consultant is insisting that all URL's (mostly dynamic) on the site must end with a trailing forward slash e.g. /home/index/
I have no idea how to implement this in Rails or if it is even a Rails task, does anyone know how this could be accomplished?
Upvotes: 0
Views: 451
Reputation: 14018
While I agree with Gareth's sentiment, there is some truth to what he says; Google will treat URLs that are different in any way as ... different. Let's say 10 sites have linked to /home/index and another to /home/index/ -- all this inbound linking Google Goodness becomes dispersed. So, there are a few things to do, all falling under the headline of "URL Canonicalization".
Note: your title says Rails 2.3 (Some of the details below may apply only to Rails 3.x).
First, here's the answer to your question: How to generate links with trailing slash in Rails 3?
But there's more, and maybe if you blow away your SEO consultant with your incredible knowledge, he'll crawl back to the slimey ooze to be amongst his kind. (Joking, I do SEO for a living -- I much prefer the zombie filled swamp).
First and foremost, all pages having the same content should have the one and only one URL. Your code needs to generate that URL in link_to
, and url_for
calls, which generally speaking Rails does out of the box.
Second, and almost as important, while multiple URLs may lead to a given page, you should choose one and ensure that the others are "Permanently Redirected" to the canonical URL. The most common case of this is that sites typically will respond to "www.example.com" and "example.com", and since this is part of your URL, you should pick one or the other, and make sure that's where it lands. The traditional way to do this is to use RewriteRules in Apache (and I think Nginx), but if you're not familiar with them, they will want to make you decide software was a bad career path, and that one of those Dirty Jobs would be preferable. Here's a gem that does it for you: https://github.com/tylerhunt/rack-canonical-host
Finally, it's a good idea to specify the canonical URL in the page itself -- there's a special link tag format documented here: http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html. The case where this tends to matter is when you're adding query-string parameters (e.g. sorting, filtering, searching, paginating, or even just for tracking) that look different to Google, but are pretty much the same page. It's not terribly hard to do, but here's a gem from a while back that you can look at if you want https://github.com/mbleigh/canonical-url
A final tip: generate a sitemap and submit it to Google and other search engines. I have used this gem and it works really well: https://github.com/kjvarga/sitemap_generator
Upvotes: 2