Wordpress & Rails don’t usually play nice together, but for maximum search engine optimization you want your blog as a subdirectory — not as a subdomain. Here’s the step-by-step guide of how we were able to get our Wordpress blog as a subdirectory of our Ruby on Rails app which is hosted on Heroku.
Example:
I would still strongly urge folks to keep all content on a single subdomain. We recently were able to test this using a subdomain on Moz itself (when moving our beginner’s guide to SEO from guides.moz.com to the current URL http://moz.com/beginners-guide-to-seo). The results were astounding — rankings rose dramatically across the board for every keyword we tracked to the pages.
Rand Fishkin, Co-founder of Moz.com, explains it best above (full answer here). In short, it makes a big difference. Get your blog as a subdirectory as fast as possible, otherwise you’re not maximimzing pageviews for the content you’re putting out.
Flywheel Management: No need to add a subdomain here. The password protection helps the search engines know to only visit the blog where you want it seen.
We have our Wordpress blog hosted on Flywheel (disclaimer: my referral link). The support is incredible, and I highly recommend them. It’ll make the rest of this a breeze.
Email Flywheel and tell them you need to setup your blog like rovrblog.flywheelsites.com. They’ll need to change the Wordpress Address and _Site Address (_these fields are locked in Flywheel from users changing them).
Ask for Dusty (one of the Flywheel founders who worked with us) if you run into any issues.
Flyhweel will need to change the URLs inside Wordpress Admin to match the proxy address.
You can absolutely host your blog outside of Flywheel, but you may have a harder time following in the guide. If you run into hiccups, I’d recommend giving Flywheel a run before scrapping the idea.
Add the rack-reverse-proxy gem to your gemfile:
gem 'rack-reverse-proxy', :require => 'rack/reverse_proxy'
Add the reverse_proxy code in your config.ru file so that /blog/ points to your blog on Flywheel.
Here’s an example of what a final config.ru looks like:
https://gist.github.com/parterburn/67e27d302b79d70272c1
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' => redirect("https://yourdomain.com/blog/")
If you had already been using a domain like blog.yourdomain.com before, you’ll also want to setup a forward for the subdomain as well:
Add to config/routes.rb:
# Only necessary if you had blog.yourdomain.com setup before:get '(*path)', to: 'application#blog', constraints: { subdomain: 'blog' }
Add to app/controllers/application_controller.rb:
def blogredirect_to "https://yourdomain.com/blog#{request.fullpath.gsub('/blog','')}", :status => :moved_permanentlyend
If needed, here’s a guide for how to Implement Routing for Subdomains.
If your existing site has SSL turned on (which it should), you’ll want to do a few more things in order to turn on SSL throughout the blog. Google is now ranking sites higher for SSL, so you should definitely take this extra step even if you are not today.
The free Simple SSL in Flywheel should suffice if your site doesn’t need the absolute maximum compatibility (or you don’t already have an SSL certificate). Otherwise, you’ll need to enable the $10/mo SSL add-on. They’ll send you a .CSR file, but you’ll also need the .KEY file in order to update your certificate on Heroku — just shoot an email to [email protected] and they’ll send it over. The site I setup had their certificate through GoDaddy, so I followed this guide to re-key it.
That updates your SSL for your site on Heroku. Flywheel will take care of updating it on their end.
You’ll want to install the two plugins on your Wordpress to force it into SSL mode:
You’ll also want to take a look at this article in order to turn back on the Visual Editor inside Wordpress.
Thanks for reading! If you need any help in getting this setup, don’t hesitate to tweet me: @parterburn.