Learn-a-holic Geek Notes

Human compiled Brainwork by Kornelije Sajler.

Octopress SEO and Disabling the Blog Route

The SEO on Octopress by default is moderate, but it can be better, too bad that the rake new_post doesn’t generate Meta description and the keywords. The other problem is redirect to single page which is broken since there is learnaholic.me and www.learnaholic.me which can affect site ranking.

The third problem is that Octopress by default has a <domain>/blog route path which is awkward and unnecessary, domain is sufficient enough without /blog.

The most SEO fixes are from the SEO for Octopress,Heroku post by Yatish Mehta.

Keywords and Description for every page

The provided keywords and description should be a goal for each page, the problem is that rake new_post doesn’t generate keywords and description, so it should be added manually.

I’ve added the keywords and description to all my posts created in this few days and the post Octopress metadata looks like this:

1
2
3
4
5
6
7
8
9
---
layout: post
title: "Make Powershell, SSH Github and git suck less on Windows"
date: 2012-10-12 03:41
comments: true
categories: [powershell, git, github]
keywords: powershell, git, github, windows, ssh key, posh-git, msysgit
description: Installing the msysgit, configuring git, creating SSH keys for Github, customize the Powershell, installing posh-git. Windows suck less after.
---

Home page Keywords and Description

The Octopress by default shows latest post as home page, I choose not to go this way, my default home page is archive list. So there is no post from where it should include the keywords and description.

Setting Keywords and Description for Home page in _config.yml

Open the _config.yml and add the kewords and description keys:

1
2
description: Kornelije Sajler (xajler) Learn-a-holic Geek Notes. Human compiled Brainwork by Kornelije Sajler (xajler).
keywords: Kornelije Sajler, xajler, metaintellect, learnaholic, learn-a-holic, coding, programming, Ruby, Ruby On Rails, RSpec TDD, cucumber, jasmine, bacbone.js, postgresql, mongodb

Change head.html template to be aware of Home page SEO

In .themes/classic/source/_includes/head.html after meta tag for author replace the current description/keywords code with this one:

Single domain rewrite

To make sure that there is no differnce between learnaholic.me and www.learnaholic.me request, we shall include rewriting with gem rack-rewrite.

To Octopress Gemfile add:

1
gem 'rack-rewrite'

To top of config.ru (before SinatraStaticServer) add:

1
2
3
4
5
6
7
8
9
10
ENV['RACK_ENV'] ||= 'development'

ENV['SITE_URL'] ||= 'www.learnaholic.me'

use Rack::Rewrite do
  r301 %r{.*}, "http://#{ENV['SITE_URL']}$&", :if => Proc.new { |rack_env|
      ENV['RACK_ENV'] == 'production' && rack_env['SERVER_NAME'] != ENV['SITE_URL']
    }
  r301 %r{^(.+)/$}, '$1'
end

Don’t forget to add a require on the top of the config.ru:

1
require 'rack-rewrite'

Complete config.ru should look like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'bundler/setup'
require 'sinatra/base'
require 'rack-rewrite'

# The project root directory
$root = ::File.dirname(__FILE__)

ENV['RACK_ENV'] ||= 'development'

ENV['SITE_URL'] ||= 'www.learnaholic.me'

use Rack::Rewrite do
  r301 %r{.*}, "http://#{ENV['SITE_URL']}$&", :if => Proc.new { |rack_env|
      ENV['RACK_ENV'] == 'production' && rack_env['SERVER_NAME'] != ENV['SITE_URL']
    }
  r301 %r{^(.+)/$}, '$1'
end

class SinatraStaticServer < Sinatra::Base

  get(/.+/) do
    send_sinatra_file(request.path) {404}
  end

  not_found do
    send_sinatra_file('404.html') {"Sorry, I cannot find #{request.path}"}
  end

  def send_sinatra_file(path, &missing_file_block)
    file_path = File.join(File.dirname(__FILE__), 'public',  path)
    file_path = File.join(file_path, 'index.html') unless file_path =~ /\.[a-z]+$/i
    File.exist?(file_path) ? send_file(file_path) : missing_file_block.call
  end

end

run SinatraStaticServer

Set the route without unnecessary /blog route path

The Octopres by defult has a weird <domain>/blog/2012/10… route path, the blog part of URL is totally unnecessary, so I removed it all together.

In _config.yml change:

1
2
permalink: /blog/:year/:month/:day/:title/
category_dir: blog/categories

to:

1
2
permalink: /:year/:month/:day/:title/
category_dir: categories

Now the url should look like this:

http://learnaholic.me/2012/10/15/octopress-seo-and-disabling-the-blog-route/

But by default it would be:

http://learnaholic.me/blog/2012/10/15/octopress-seo-and-disabling-the-blog-route/

Conclusion

Improved SEO of the Octopress site:

  • Including the keywords and description to each post.
  • Home page is now with keywords and description, generic for the whole site.
  • Redirect to single domain. The www.learnholic.me request will be redirected to learnaholic.me.

The cleaner site path by removing the unnecessary /blog from the URL route.

Comments