add wordpress blog

How to add a WordPress blog to a Ruby on Rails app?

While Ruby on Rails is what’s best to build a web app, WordPress is number #1 when it comes to blogging. And these days, a great start-up must have a blog alongside its main app. So, let’s see how to add a WordPress blog to Ruby on Rails.

Why should I have WordPress on Rails?

There are several different reasons justifying why you really should have a blog, a WordPress one.

Communicate with your users

A blog -together with social media- is by far the best way to start a conversation with your users, to give them some insights or simply to communicate your latest news.

Your best ally for SEO

In today’s SEO, content is king. A blog is the best way to put a content marketing strategy in place, and having one is important for improving your Rails SEO. It enables your company to share its knowledge using the right keywords. As a result, your website is much easier to be found by users in the SERPs.

You can check out this article from KissMetrics : Why SEO Is Actually All About Content Marketing

Choose WordPress for a complete yet simple solution

A blog can definitely be built using Rails only (if you choose to go this route, take a look at Octopress). But WordPress is already so well optimized and ready to use in a few clicks, that you probably don’t need to do it on Rails.

Building your own blog solution, or using some Ruby on Rails projects, might still be the best option if you want an entire Rails integration (login, etc…). Or maybe you particularly enjoy doing it. Otherwise, and the vast majority of case, it is just unnecessary additional work. WordPress on Rails is the best solution for these cases.

You may want to read this article by the well-known ThoughtBot team, who goes through all possible solutions before actually deciding to go with their own blog solution.

Setting up a WordPress blog on Ruby on Rails in a few steps

Adding a blog to an existing website isn’t actually complicated process. But you do have to follow these steps and you can’t miss one.

Migrate your existing blog to Flywheel, or create a new one there

The blog I wanted to add to my Rails app was already existing, but hosted on a service that wasn’t convenient to use in this case.

I chose to migrate this blog to Flywheel (or you can create a blog directly there if you don’t have one). They have a very simple process to do that, and the support team is very helpful. I was concerned about moving the blog, but eventually did it without any problem.

Of course, you are free to choose another hosting service. Flywheel is the one I tested and approved but I’m sure there are other good solutions out there.

When it’s done, you will have a new blog URL (ie: First, you will want to redirect this URL to your Rails app.

Should I have my blog in a subdirectory ( or a subfolder (

Choose the subfolder. It has been proven to be better for SEO (as far as we can prove something in SEO).

Tell your choice to the Flywheel team so they can do what needs to be done on their side. They will put the settings in place to allow the WordPress site on Flywheel to load from Otherwise your links will point to this WordPress blog on Flywheel.

On your Rails app

Add the rack-reverse-proxy gem to your gemfile :

gem 'rack-reverse-proxy', require: 'rack/reverse_proxy'

Then, you need your Rails app to redirect /blog/ to your Flywheel site. Go to and add the following code:

use Rack::ReverseProxy do
                opts = { preserve_host: true })

Note: Make sure you don’t have a trailing “/” in your URL. It should be$1 and not$1

Last thing, in config/routes.rb, you need to redirect /blog to /blog/. Add this line:

get '/blog', to: redirect('', status: 301)


Voilà, you have your beautiful blog alongside your powerful Ruby on Rails app.

There are a few SEO gotchas you should be aware of to avoid loosing your rankings in search engines. Mainly, you will have to redirect your articles to their new url.

You can do this simply inside config/routes.rb:

get '/my-article', to: redirect('/blog/my-article', status: 301)

There you go. I hope this article has been useful for you. I will keep it updated and add more relevant info in it. Don’t hesitate to ask me any question in the comments below.

How to add a WordPress blog to a Ruby on Rails app?
4.6 (91.67%) 12 votes

2 replies

Trackbacks & Pingbacks

  1. […] the way, it might be a good idea to add a WordPress on your Rails app, for your […]

  2. […] his blog and/or Twitter, a coder can take time to explain and transmit coding skills to others. That’s […]

Comments are closed.