These days, a great blog alongside its main web app is a must have for any SaaS provider. While Ruby on Rails is best when it comes to building a web app, WordPress is number #1 when it comes to blogging.
Why WordPress on Rails?
A blog can definitely be built using Rails itself. But WordPress is already so well optimised and ready to use in a few clicks, that you don’t need to do code a blog from scratch.

Building your own blog solution, or using some existing gems, might still be the best option if you want an entire Rails integration (login, etc…). Or maybe you particularly enjoy doing it. Or maybe you require a very simple version of a blog. Otherwise, and the vast majority of case, it is just unnecessary additional work. WordPress on Rails is the best solution for these cases.
Best WordPress + RubyOnRails Setup
Wordpress & Rails don’t usually play nice together. So the best option is host RubyOnRails web app on your root domain and host WordPress blog on a subdomain.

For example:

A Ruby on Rails app can be hosted on Heroku:
A WordPress blog can hosted on WPEngine:

You can obviously host both main and sub-domain on single server as well. Netling’s website and client login is built on RubyOnRails and our blog is running on WordPress hosted on a single DigitalOcean VPS instance managed with Plesk Onyx AdminPanel.

However, this is not an ideal situation. For maximum search engine optimisation you want your blog to be accessed as a subdirectory — not as a subdomain. So essentially you want to achieve something like this:

A Ruby on Rails app hosted on Heroku:
A WordPress blog hosted on WPEngine:

This brings us to the main question,

How to host a RubyOnRails app on a root domain and a Wordpess blog on a subdomain and still be able to access blog as a sub-directory?

The answer is, put WordPress blog behind a reverse proxy!

Setup root domain server hosting RubyOnRails app as reverse proxy to forward all requests made for your blog to subdomain running WordPress. For example, setup as a reverse proxy to forward any requests made to to

Typically, this requires changing configuration of your Apache or NGINX instance, but we will use a handy rails gem to achieve the same results – rack-reverse-proxy .
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 WordPress blog on subdomain. Go to and add the following code:
use Rack::ReverseProxy do
reverse_proxy(/^\/blog(\/.*)$/, ‚$1‘, opts = { preserve_host: true })
Note: Make sure you don’t have a trailing “/” in your URL. It should be$1 and not$1

Since the blog is technically hosted at /blog/, we need to forward the /blog requests there (notice the non-trailing slash).

Add to config/routes.rb:

get „/blog“, to: redirect(‚‘, status: 301)

On your WordPress blog
In your wp-config.php add following lines:

* Handle SSL reverse proxy
if ($_SERVER == ‚https‘)

if (isset($_SERVER)) {

$_SERVER = „/blog“.$_SERVER;

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

Thanks for reading! I will keep it updated and add more relevant info in it as needed. If you need any help in getting this setup, don’t hesitate to tweet me: @netlings.