There are many ways to improve the SEO for Ruby on Rails.
And SEO is one of the best free ways to gain new customers for a start-up.
So here is a guide with many tips to improve Rails SEO.
There are numerous quick wins to be made, and spending a few minutes on those can dramatically improve your rankings in Google and other search engines. We tried to bring everything that can be useful for a Rails app.
Technical SEO for Ruby on Rails
Rails SEO (Search Engine Optimization) is meant to use various technical tools to help ranking higher in search engines results page. If two websites in the same business sector perform differently in search results, it might be because one is optimized for SEO but the other is not.
SEO can be divided into two categories: the content side and the technical side. Here, we will focus on the technical side, because we are developers and the Ruby on Rails app is our responsibility.
But it’s important to remember that Google loves content. High-quality content. And a perfectly technically SEO-optimized Rails app won’t rank high in SERPs (Search Engine Results Pages) if it doesn’t have quality content to give to the search engines.
Now, given that you have awesome content, let’s see how you can give it all the chances to rank high and attract potential customers to visit your app thanks to a good technical SEO for Ruby on Rails.
Rails is not so good for SEO out-of-the-box
Unlike WordPress, which is optimized to rank well from the moment you start using it (there are still a few tweaks to be made, but that’s for another article), Ruby on Rails needs you to work on this aspect.
When you start a new Rails app, your website as major SEO problems: no sitemap, no user-friendly URLs, no meta-tags, and so many things you must be careful when you build your layout and views. Things that WordPress is doing for you.
- By the way, it might be a good idea to add a WordPress on your Rails app, for your blog.
But, while you need to set things up yourself with Rails, you also have greater power on how they are implemented. And that will turn to your advantage once you know how to use it. So, let’s not wait for it any further and start improving your Rails SEO skills.
5 Tips on How to Improve SEO for Ruby on Rails:
These “tips” could be called “must-have”. Without them, you have very little chances to rank well in Google. Bookmark this article, take some time to implement these techniques, and you will be rewarded.
1. User-friendly URLS
By default, the URLs in Rails show the ID of the object. That’s bad from an SEO perspective. Nice, meaningful URLs are a good way to tell both users and search engines what the page is about.
You will want to have this URL: “mydomain.com/why-my-product-is-awesome”, not that one: “mydomain.com/pages/12”.
The best way to take care of is using the gem friendly_id. It will allow you to give a slug to an object, which will be used to build the URL. You can then find this object by its slug.
2. Meta-tags (title, description, no-index, etc.)
Meta-tags are essential in your SEO for Ruby on Rails app or any other website. There are a lot of them, but just a few are really useful. Let’s walk through them.
Title: This is the title of the page, the one you see in your browser’s tab. It’s what the search engine will display in the results. It is very important to get this right, or you might confuse both users and Google.
Description: Mostly, this is what will be displayed in the SERPs, below the blue title and the green URL. Like for the title, make it count.
Noindex: It tells Google bots and others to not index your page, so it does not appear in the SERPs. There are many reasons why you wouldn’t want to index a page. One of the most common is to prevent duplicate content and thin content penalties.
Viewport: It’s necessary to improve the user experience on mobile. It’s one of Google’s ranking factors.
It’s very important to get these right if you want to rank. To be efficient, you can use the gem ‘meta-tags’ to our Gemfile. It will allow you to customize and make use of those meta-tags in Rails.
Here is a good article by Cookieshq.co.uk that will help you set it up.
3. Add a Sitemap
A sitemap will help search engines and other bots discovering your content. It’s like a list of your content. Without it, robots will have to crawl your site using only the links in your content.
As a result, deep pages (several clicks away from the homepage) and pages without direct links are much less likely to be found, which hurts your Rails SEO.
4. On-page factors
A critical aspect of SEO for Ruby on Rails, in between the content and the technical parts. In WordPress, most templates are designed to make you follow good SEO practices without even noticing. The blog post title will be put as an H1, you won’t have to think about using the HTML5 tags, etc.
But you will have to build those good practices inside your Rails app. Let’s review the on-page SEO optimizations you need to be aware of.
Header tags: Don’t just style your titles with CSS, mark them using HTML tags. Always use an “h1” for your main title. Then, you can go down from “h2” to “h6”.
Despite what you can read sometimes, you don’t risk a penalty for using multiple h1. But it’s not a good practice to do it, as the relevance of your keywords will be diluted.
Although the header tags are now a little less important than they once were, you should still definitely use it, especially the h1 tag.
HTML5 Semantic Elements: Use the semantic HTML to help search engines figuring out what’s important on your page and what’s less.
Nothing official, but it’s largely thought that Google uses it to give more or less power to the content (and its links) depending on the tag. It would give more power to what’s in between the
<header> tags and less for the
Other interesting tags are
This article being about SEO for Ruby on Rails, let’s see how to best use HTML5 semantic tags.
Let’s say you have an article page with a navbar, a sidebar, a nice article and a footer.
Go to layouts > application.html.erb and modify it to this:
<head> <!-- Where the meta-tags will go --> </head> <body> <header> <nav> <!-- Your navbar --> </nav> </header> <main> <article> <%= yield %> <!-- Your article --> </article> <aside> <%= content_for(:sidebar) %> <!-- Your sidebar --> </aside> </main> <footer> <!-- Your footer --> </footer> </body>
Of course there are many different ways to organize your content architecture, but this is a pretty solid one.
5. Honorable mentions about Rails SEO
With the above, you will have overcome the main SEO “shortcomings” that Rails has out of the box.
Of course, there are still work to do to improve Rails SEO. Here are some interesting pieces. Some more details about them might be added in a future version of this article.
- HTTPS: 50% of page-1 Google results are now HTTPS, according to Moz experts. Switching from HTTP to HTTPS is more than just a Rails problem. On the Rails side, you can force SSL. Then, you will have to purchase a SSL or use a free one (those are increasingly available). If you use Heroku, check out this article.
- Speed: Google included page speed as one of the ranking factors. But it’s a much bigger issue than just Rails SEO. You will need to work with server-side caching, client-side caching, jQuery and CSS files, CDN… There is a lot to do, and that could be a long article itself. In the meantime, check out this one and that one.
In conclusion, your Rails app is now much more likely to rank in SERPs. You are ready to make in fly high in Google’s search results. But always keep in mind that technical SEO is here to serve quality content, they go hand in hand.