Rails SEO Guide

Never launch another Rails app without working on SEO first. Check our guide to learn how to build a search-optimize Rails app.

There are many channels that can attract users to our sites, but organic traffic is surely an attractive alternative: users can discover our solution while searching for a problem they're currently experiencing.

SEO is the process of optimizing our site using on-page and off-page factors and its content to generate traffic from search engines

Let's start by understanding the relation between Rails and SEO:

Rails and SEO

Because Rails is a full-stack framework that renders HTML server-side, there's nothing exceptional about it when it comes to SEO.

With the correct configuration and site structure, there's really no difference between Rails and other CMS alternatives.

Since Rails isn't a CMS, we need to implement content and SEO-specific features ourselves if we want our content to be indexed and rank.

With Rails, we're mostly concerned about on-page SEO factors and providing an appropriate user experience so let's see what on-page SEO is about and how we can optimize it in Rails apps:

On-page SEO

On-page SEO is the process of optimizing what we render, the content, and how we render it considering search engines and the way they work.

Our main concern with Rails is how we structure our pages and their markup and the user experience we provide: speed, usability, accessibility, etc.

Search engines crawl our site and index our pages using the HTML that we render and they use the content itself and the markup to understand what our pages are about and if they're relevant to the user's query.

We can optimize on-page SEO in Rails by considering:

HTML tags

Using proper HTML tags is probably the most important on-page optimization.

The main concept to understand is that HTML tags can be used to establish a content hierarchy which mainly revolves around heading tags.

Use them to organize the content to make it easier to consume and understand at a glance: most users will skim your content before deciding to read it.

Some tips that you might find useful when deciding which HTML tags to use are:

  • Use only one H1 heading: this heading is the most significant tag of every page. It should only be used once, and it should also convey what the page is about. For example, if we are creating a page about Rails Authentication, our H1 tag should contain the Rails authentication keyword and appear only once on the page.
  • Use headings to organize the content: within the content, use headings in descending order to organize topics and concepts. Avoid nesting too many headings: sticking up to level 4 headings is probably a good recipe. If you find yourself using more nesting, you probably have to think a bit more about the content hierarchy.
  • Use semantic tags: whenever possible, use semantic tags to represent entities. Use an article tag to represent a self-contained composition or a blockquote to represent a quote.
  • Links: as long as they are relevant, links are a great way to add value to our pages. They can help users discover resources that might be useful to them, navigate through a site to find what they're looking for and learn a topic in depth. Adding internal links to other pages of our site is a good way to help users and search engines understand the structure of our site and how pages relate to each other.
  • Images: images are a great way to add value to our pages. They keep users engaged while also helping them digest our content and learn faster. They also increase the time users spend on our pages, which is a ranking factor. Don't forget to optimize your images size, making them lazy loaded and add an alt text to your images to help search engines understand what they're about. For blogs or long-form content, adding a lightbox feature can also help users and make your site more engaging.
The H1 tag should match the page title, be unique among other pages and be inspired by keyword research. Keep your hierarchy to 4 levels or less unless you absolutely need to. Never try to fool search engines with hidden content or tricks of the sort.

Meta tags

Meta tags are HTML tags that provide information about our page to search engines but that are not directly displayed to users.

Whenever we perform a search, search engines use the meta tags we provided to produce the title and description of the search result that is shown to users.

Nowadays, search engines use meta titles as a directive but often rewrite meta descriptions to make them more relevant to the user's query. However, optimizing both to clearly communicate what a page is about and what value it provides to the user is always a good SEO practice.

If you want to learn more about them, don't hesitate to check our guide on meta tags for Rails applications:

Cover photo for the Add meta tags to a Rails applications post

Add meta tags to a Rails applications

Meta tags are important for SEO. Learn how to add them to a Rails application in this article

Friendly URLs

In SEO, friendly URLs are short and readable URLs that we use to represent what a page is about.

They're meant to be easy to remember and share and they can help us rank because they help users and search engines better understand the content of our pages.

A good example of a friendly URL is something like /blog/friendly-urls-in-rails while an example of a not so friendly URL looks something like /articles?id=48.

Assuming both of these URLs produce the same content, the first is clearly more helpful than the second.

In Rails, there are many ways to produce friendly URLS but using the friendly_id gem is probably the most common and simple of them all.

Check our article on friendly URLs to understand how to add them to your Rails apps:

Cover photo for the Friendly URLs with the FriendlyId gem post

Friendly URLs with the FriendlyId gem

Learn how to implement friendly or pretty URLs using the FriendlyId gem for your Rails application

Sitemap

A sitemap is an XML file that lists the pages of our site that we want to get indexed by search engines.

Even though search engines can crawl our site without a sitemap, it's a good practice to provide one because it helps them understand the structure of our site.

However, adding a sitemap is no guarantee that content will be indexed: we have to make sure that the pages are accessible, the content is relevant and that we're not blocking search engines in any way.

We can generate a sitemap in Rails using the sitemap_generator gem. It's a simple gem that can generate a sitemap.xml file that we can then serve to search engines.

Cover photo for the Adding a sitemap to a Rails application post

Adding a sitemap to a Rails application

Sitemaps are an important part of optimizing our Rails app for SEO. Let's learn how to add one to a typical Rails app and host it on the cloud

Canonical URLs

When it comes to SEO, a canonical URL is the preferred URL for a page when multiple versions of the same content exist.

Because a given page can produce many different, yet slight, variations of the same page, we use canonical URLs to tell search engines about which one of them we want to be indexed.

For example, we might have a page that displays a product that has multiple variations like size, color, resolution, etc. If each URL has search traffic and produce sufficiently different content, we can have them indexed by adding a self-referencing canonical URL.

On the other hand, if we find that people are not searching for the individual variant's we can use a canonical URL that references to the main product page or primary variant. Using this, search engines won't index the individual variant's URLs.

In Rails, adding canonical tags is not technically difficult but it requires that we do a previous study to define a strategy based on keyword research and the type of content we're dealing with.

Learn more about canonical URLs in Rails with the guide we wrote:

Cover photo for the Canonical URLs in Rails applications post

Canonical URLs in Rails applications

Let's learn about canonical URLs in Rails apps: how to add them and some things to consider when adding them to our sites.

Structured data

Schema markup, also known as "structured data" is a way to provide information about our pages to search engines in a structured format.

We can think about it as meta tags for structured content, meaning we can provide information about entities that our pages represent like: website, author, article, frequently asked question, breadcrumb, etc.

Just like meta tags, this information is not directly displayed in our pages but it can help search engines better classify and display our content using it.

For example, our site might display a list of books. Using structured data, we can tell search engines about it and have them represent our pages as books with an author, reviews, page count, ISBN, etc. in the search results page.

We wrote a complete guide to structured data for Rails applications, check it out so you can add it to your Rails app and improve your SEO results:

Cover photo for the Adding Structured Data to a Rails application post

Adding Structured Data to a Rails application

Learn how to add Structured Data to a Rails application and improve your SEO results without much effort

Table of contents

A table of contents is a list of the main topics and subtopics of a page. It's a good way to help users navigate the page and quickly find what they're looking for.

It also helps search engines understand the structure of our pages and how topics are related to each other. Plus, it forces us to think about the content hierarchy and write better content by considering it before writing.

The added benefit is that it can help us rank better because users are more likely to stay on the page knowing what they're going to find on it by reading the table of contents.

We wrote a complete guide on how to add a dynamic table of contents using Rails and Nokogiri:

Cover photo for the Dynamic Table of Contents with Nokogiri post

Dynamic Table of Contents with Nokogiri

Adding a table of contents is usually a nice way to help our users navigate our content quicker. In this article we will learn how to add one to a Rails app using the Nokogiri gem to build a PORO responsible for generating the TOC

Off-page SEO

Off-page SEO is the process of getting other sites to reference our content through links. Search engines use these links to understand the relevance of our content and to assign an authority score to our site that's used, among many other factors, to rank our pages.

There's not much we can do about off-page SEO in Rails. However, we can still improve our site's visibility and chances of getting noticed by:

  • Provide a good user experience: if our site is fast, easy to use and offers content that's relevant and digestible, we increase our chances of obtaining backlinks and mentions.
  • Create unique resources: as developers, we can work on creating tools and resources that go beyond the typical blog post. These kind of assets can be very useful and get us noticed.
  • Make the content easy to share: adding share buttons to our pages doesn't require much effort and can improve our chances of the right people noticing our content.
  • Getting results with off-page SEO can take a while and there's no guarantee that we'll get the results we want. However, if we focus on the user and the value we provide, our chances improve considerably.

SEO in the LLM era

The rise of LLMs has changed the way we think about SEO. Traffic for informational queries seems to be dominated by LLM summaries.

Some sites have seen steep declines in traffic to their sites, especially for information queries. This doesn't necessarily mean that focusing on SEO is worthless, but it does mean that we need to adapt our strategies.

Providing concise, high-quality content that's easy to understand and digest is a good way to improve our chances of getting recommended by LLMs.

On top of that, focusing on keywords that have less volume but more commercial intent is a good way to work with SEO in a time where information queries are dominated by LLMs.

A good way to help LLMs understand our content is to add a llms.txt file to our site:

The llms.txt file

The llms.txt file is a special file which offers an LLM-friendly version of our site's content.

It allows us to provide a compressed and machine-readable version of our site's content that's easier for LLMs to understand and process.

According to the proposed standard, the file wouldn't be used at the time of training but it would be used at the time of serving the content to LLMs.

We wrote a complete guide on how to add a llms.txt file to your Rails app:

Cover photo for the Adding llms.txt to a Rails application post

Adding llms.txt to a Rails application

Let's learn how to add a llms.txt file to a Rails application to help large language models better process our content

Other ranking factors

Search engines use a large number of signals to determine how relevant a page is for a given query. Some studies like 200 Ranking Factors: The Complete List by Backlinko mention more than 200 factors.

Google's May 2024 API leak revealed over 14,000 attributes and features the Google search algorithm uses to rank websites.

Some of the most important ranking factors are:

  • Content quality: as subjective as it can be, content quality is a major ranking factor. Search engines judge the content using a set of inherent qualities and proxy factors like engagement, time on page, bounce rate, etc. As cliche as it may sound, focus on writing useful content that provides value to users and SEO results will usually follow.
  • Backlinks: links from other websites to our page are a major ranking factor. They act as a vote of confidence from other websites. Gaining backlinks from a number of high-authority websites can help us rank better.
  • User experience: how users experience our site is a major ranking factor. This includes how fast our site loads, mobile-friendliness, how easy it is to navigate, how engaging our content is, etc.
  • Schema Markup: also known as structured data, schema markup is a way to provide information about our pages to search engines in a structured format. It helps search engines understand the content of our pages and occasionally display it using rich snippets in search results. It's a rather indirect ranking factor but adding them is helpful.

Summary

SEO is a complex topic and its only certainty is that it's always changing. However, focusing on the basics and creating content that provides value to users is usually a good way to achieve success in the long run.

Even if Rails SEO is about implementing some technical features that we can put into a checklist, knowing about the underlying concepts is always helpful even if we're not in charge of the SEO of our site or application.

In this guide we covered the basics of SEO for Rails applications: meta tags, friendly URLs, sitemaps, canonical URLs, structured data, breadcrumbs, table of contents, LLMs, and other ranking factors.

We also covered some of the frequently asked questions about SEO for Rails applications. If you think we missed something, please let us know so we can update the guide.

We hope you found this guide useful and that it can help you improve your SEO results using Rails.

Build with Avo

The Essential Toolkit for building Internal Tools with Ruby on Rails

Building boilerplate features is a messy, boring, and time-consuming process. Focus on the more unique aspects of your business and ship faster with Avo.

Frequently Asked Questions

The following are the most common questions when it comes to Rails SEO. Feel free to reach out if you want any question answered here.

Rails and WordPress are not really any different when it comes to SEO. In the end, they're applications capable of generating HTML server-side.

WordPress is usually recommended for SEO purposes because, by default, it has a somewhat SEO-friendly configuration, and there are many plugins in the WP ecosystem that can guide users to obtain better SEO results when they're not experienced with the matter.

However, with an appropriate configuration and site structure, there's really no difference between Rails and WordPress. We can even argue that a properly set Rails app can be better for SEO than WordPress because they're typically leaner and faster, especially when we consider that a significant number of WordPress themes and plugins are not optimized for performance.

Of course, Rails is not a CMS like WordPress is: using a Rails CMS or working on the application to add CMS features is required to achieve a basic feature parity.

When it comes to the plugin ecosystem, there are many plugins in WordPress that solve basic on-page issues like sitemaps, canonical URLs, or redirections. A Rails SEO-ready application should solve each one of those issues without the need for plugins.

But there are some plugins that can be useful when creating content by guiding users to create optimized content when it comes to keyword usage, internal linking, etc.

There are no widespread alternatives to those plugins in Rails, but having a content strategy and guidelines can replace them, especially with the latest search engine updates that prioritize natural content instead of keyword optimization like in the past.

To sum it up: WordPress is not better at SEO than Rails is or any SSR framework is. That is a myth rooted in the fact that WP defaults are a decent starting point and that it was better suited for SEO beginners when other alternatives didn't consider SEO upfront.

The way to structure content for SEO purposes can vary depending on the type of site we're making. However, as a rule of thumb, we can define our root URL and link to our main content categories or subcategories from there and then map a reasonable navigation path from there on.

There are mainly three architectures to organize content:

  • Hierarchical architecture: this is very typical and intuitive. The content is organized in a tree-like structure. The root page is the homepage, and we link to the main categories and subcategories from there.
  • Topical clustering: the page you're looking at right now is a good example. It's a page centered around the Rails SEO topic that links to content about the topic. They are good for search engines to understand how content relates to certain topics, and they can also be a source for links because they organize the content practically for users.
  • Silo architecture: it's a hierarchical architecture where the topics are contained to themselves without much interlinking between the silos. For example, we might have a trip page with silos for “things to do in #{city}" where each city would link to hotels and restaurants, but links between silos are avoided to help crawlers understand the relation between the content.
  • Generally speaking, thinking about the user and making the navigation experience as friendly as possible to make sure they can find what they're looking for produces good site architectures.

    When in doubt, don't hesitate to see how other people with good SEO results are structuring their content and copy them.

No, there’s no need for any special tools to optimize a Rails application for SEO purposes.

There are some tried and tested libraries like friendly_id or meta-tags that can help us save time but they're not required.

If you want to work on off-page SEO or know which keywords you should target to reach your prospective customers, there are many services that can help you with those tasks but they are not related to Rails at all.

Not really, having a blog is not necessary to have an SEO-optimized Rails site. There's nothing special about a blog itself. What finally ranks is the content, especially if it helps users find what they're looking for.

You can create content and organize it as you see fit without having what's traditionally thought of as a blog.

Furthermore, your database can be a source of content: listings, comparisons, or user-generated content.

However, having a blog can be good for the following reasons:

  • It can help us organize content: just by imitating how blogs are usually put together we are probably generating a decent content architecture by grouping related topics together using categorization.
  • Anyone can write using a CMS: with a CMS, even if it's rudimentary or made in-house, writing is encouraged, and anyone from the team can write and produce useful content that gets ranked.

Having an organized section on our website where non-technical users can add content is generally positive, even if it's not called a blog or if it doesn't sit at /blog.

It depends: if you are working alone, with people that are familiar with HTML/ERB, or you're using a CMS, you can safely use Rails for your marketing site.

However, there are a couple of scenarios where decoupling your marketing site from your Rails application can be wise:

  • You need many landing pages: there are alternatives besides WordPress for creating landing pages with visual editors, but they're usually pricier than their WP alternatives, and they can add an unnecessary layer of complexity to our application.
  • Using a subdomain for your app is ok: the most practical way to add WordPress for the marketing site is to have a WordPress app responding to requests on the root domain and having our Rails app a subdomain like `app`. For a practical example: if your app is a SaaS where you don't care that much about user-generated content, you can safely use a subdomain. If your app is more like a directory (AirBnB) or an e-commerce app, you might want to consider other alternatives because subdomains can make ranking more difficult for most applications.
  • You plan to outsource marketing: if you want to outsource website-related marketing, it's very probable that people that work in the area have experience with WordPress and might even be reluctant to learn about other content management systems.

Considering this, there are many cases where using Rails for the whole thing is a good fit.

If you're a Rails developer just starting out with a project and don't even have customers, don't complicate yourself and use Rails until the need arises. Performing a migration down the line is preferable to handling two stacks for an app with no or few customers.

The short answer is: maybe.

If you're using Rails in API mode and rendering your React application in the client, search engines might need more resources to crawl your content and that can impact your crawl budget which is undesirable.

The solution for this is to enable server-side rendering, meaning that the React application gets evaluated in the server and returns HTML instead of being mounted after the browser is loaded.

If you're using libraries like Inertia Rails or Superglue, which help integrate React into Rails without losing most of what makes Rails attractive, check their documentation to understand how to add SSR and avoid having this issue.

Of course, if you're using React for specific parts of your application but the pages you want to rank are not rendered with React, you're probably safe.

Make sure to check if your marketing pages are returning HTML instead of an application shell using the following command: curl -H "Accept: text/html" YOUR_URL_HERE.

It depends: Rails certainly optimizes static assets like CSS or JavaScript files using minification and compression out of the box, but it doesn't optimize assets like images, fonts, etc.

We can achieve better performance loading images by putting a CDN in front of our application, but to achieve better results it's recommendable to compress images, avoid using big images for small resolutions, and think about payload size for every page we build.

Consider that, even though Rails performs some asset optimization, that doesn't mean that we don't have to worry about the client-side code we are loading for each page: we should always try to load as little JavaScript and CSS as possible for each view. Especially when dealing with marketing-related views.

Yes! Rails is actually very well suited for programmatic SEO. Rails MVC architecture, its amazing routing and templating lend themselves very well for programmatic SEO.

Many companies like Airbnb have used Rails to build programmatic SEO strategies that brought them massive amounts of traffic by producing useful content with the data they already have which can be user-generated.

The main thing to consider when using Rails for programmatic SEO is to find an idea and do thorough keyword research to decide which content to generate and publish.

The next step is to create a useful and nice-looking template that provides users with helpful information while also making our product or solution known at the same time.

Then, using clever Rails routing and appropriate internal linking, we can generate a great programmatic SEO strategy.

Of course, we also have to make sure that our pages are fast and offer a good user experience, especially on mobile.

Finally, follow our sitemaps for Rails applications guide so the generated URLs get indexed, but consider that it may take a while for the site to index completely.

As of today, there are many CMS alternatives in Rails but many of them seem to be outdated or not maintained anymore.

SpinaCMS is probably the most popular alternative which currently works with Rails 8. It's a Rails engine that allows us to generate a UI that can be used by our content creators to produce pages, and we can use those pages to render our views with custom theming accessing the resources created by the CMS.

Other alternatives like SitePress are interesting, but they are better suited for technical users or developers that are not afraid to touch an editor or write in Markdown.

The other alternative is to use a headless CMS and integrate it into our application. There are dozens of alternatives, most of them paid or self-hosted, and integrating them into our application is certainly not a simple task.

If you're looking for a Rails CMS that integrates well within your application and that can even help you build it, don't hesitate to try Avo and see how you can build a great CMS with it.

Customer success stories

Find out why more than 200 companies use Avo to build internal tools and applications quicker and better.

I just wanted to say I love working with Avo in RubyGems admin panel
Maciej Mensfeld

Maciej Mensfeld

RubyGems.org Security

Avo just worked great. We were able to plug things together really easily, and it's given us the flexibility we needed to build out a really rich product
Tom Coates

Tom Coates

Head of Engineering

BBC Maestro

Avo has allowed the RubyGems.org team to build internal tools incredibly quickly, which is especially important due to our limited resources
André Arko

André Arko

RubyGems.org Team Lead

We are migrating from ActiveAdmin to Avo and both in terms of Developer experience and User experience, it is a game changer!

Adrien Poly

Adrien Poly

CTO

Plume

Avo has let me push further on the features my users benefit from most whilst trusting I am giving volunteer curators a backend experience I can still be proud of.

It's a real multiplier on the project and adopting it was undoubtedly the best technical decision we've made.

John Bannister

John Bannister

Rails developer

Exlibris RPG

I've spent time looking into solutions that complement a sensible modern stack that gets you to the point of focussing on the product you're building sooner and does not induce conceptual compression along the way.

Avo fits nicely into that stack.
David Teren

David Teren

Rails developer

I just wanted to say I love working with Avo in RubyGems admin panel
Maciej Mensfeld

Maciej Mensfeld

RubyGems.org Security

Avo just worked great. We were able to plug things together really easily, and it's given us the flexibility we needed to build out a really rich product
Tom Coates

Tom Coates

Head of Engineering

BBC Maestro

Avo has allowed the RubyGems.org team to build internal tools incredibly quickly, which is especially important due to our limited resources
André Arko

André Arko

RubyGems.org Team Lead

We are migrating from ActiveAdmin to Avo and both in terms of Developer experience and User experience, it is a game changer!

Adrien Poly

Adrien Poly

CTO

Plume

Avo has let me push further on the features my users benefit from most whilst trusting I am giving volunteer curators a backend experience I can still be proud of.

It's a real multiplier on the project and adopting it was undoubtedly the best technical decision we've made.

John Bannister

John Bannister

Rails developer

Exlibris RPG

I've spent time looking into solutions that complement a sensible modern stack that gets you to the point of focussing on the product you're building sooner and does not induce conceptual compression along the way.

Avo fits nicely into that stack.
David Teren

David Teren

Rails developer

We are heavily used Avo Pro in order to build a new "admin first" platform that can be managed by our non-tech team with ease.

The interface is extremely intuitive and can be extended fast with custom actions.

Paul Werther

Paul Werther

CTO

greenhats GmbH

I would never build a custom admin panel in the future.
We wasted too much money and could not focus on our main business.
Jonas Reif

Jonas Reif

Co-Founder

Upspeak.de

Adding Avo to my project was like adding multiple developers to my team - and that's before I even purchased a license!
Caleb Harrison

Caleb Harrison

Ruby and Crystal Developer

Avo has allowed us to develop and release apps rapidly even with very few developers working on them. We can focus our efforts on domain logic and custom design where it really matters. Every other Rails CMS is difficult to style or scale or add custom fields, but Avo has been a dream throughout. It's been a game-changer for us.
Iain Beeston

Iain Beeston

CTO, Thrivve Partners

I can't believe I just learned about Avo! After trying it for 10 minutes, it was the easiest purchase ever. I used RailsAdmin before and had so many upgrading issues. Besides that, Avo is so much simpler to configure and build.
Michael Koper

Michael Koper

Founder of nusii.com

I often think of it as... just having in-house designer, a front end, and a full stack. And AVO just gives you this with a very nice DSL where you just save time. So that's what's nice about it. Every time you use it, you save time

Mike Eyrikh

Mike Eyrikh

Tech Lead

Guestit

We are heavily used Avo Pro in order to build a new "admin first" platform that can be managed by our non-tech team with ease.

The interface is extremely intuitive and can be extended fast with custom actions.

Paul Werther

Paul Werther

CTO

greenhats GmbH

I would never build a custom admin panel in the future.
We wasted too much money and could not focus on our main business.
Jonas Reif

Jonas Reif

Co-Founder

Upspeak.de

Adding Avo to my project was like adding multiple developers to my team - and that's before I even purchased a license!
Caleb Harrison

Caleb Harrison

Ruby and Crystal Developer

Avo has allowed us to develop and release apps rapidly even with very few developers working on them. We can focus our efforts on domain logic and custom design where it really matters. Every other Rails CMS is difficult to style or scale or add custom fields, but Avo has been a dream throughout. It's been a game-changer for us.
Iain Beeston

Iain Beeston

CTO, Thrivve Partners

I can't believe I just learned about Avo! After trying it for 10 minutes, it was the easiest purchase ever. I used RailsAdmin before and had so many upgrading issues. Besides that, Avo is so much simpler to configure and build.
Michael Koper

Michael Koper

Founder of nusii.com

I often think of it as... just having in-house designer, a front end, and a full stack. And AVO just gives you this with a very nice DSL where you just save time. So that's what's nice about it. Every time you use it, you save time

Mike Eyrikh

Mike Eyrikh

Tech Lead

Guestit