Updating Permalinks in Ghost

When I think about blogging, there is perhaps no more important feature or concern than impacts to SEO. It’s perhaps one of the biggest concerns many will likely experience when performing a migration to the Ghost blogging platform.

I recently migrated my personal blogs to this platform and share some insights into the installation process in case you want to give it a go.

As you might expect, it’s had it’s up’s and down’s, much like when I first got started with WordPress. Needless to say, I’ve been making my way through it over the past few days. I’ve learned a number of things, and one such thing pertains to permalinks.

A permalink is the link to an individual blog post.

Here is an example: https://perezbox.com/2014/12/ghost-blogging-for-the-future/

The challenge I had is that the content I previously had was setup to follow a very strict permalink structure:

>/%year%/%monthnum%/%postname%/

This is how WordPress captures it, and this is what it looks like in your WordPress Dashboard:

In Ghost however, things are a bit different.

Configuring things like Permalinks might appear a bit daunting, and they technically are at first, but once you’ve figured it out, it’s easy moving forward. You find your Permalink option in Ghost under the Settings dashboard, but it leaves a lot to be desired:

By default, the structure is going to be /Year/Month/Day/Post Name. If you care about SEO then you know how disastrous this can be. (hint: the issue is the introduction of the Day value). That one value will likely break your previously cached and linked posts/pages, generating a number of 404’s and possibly a nightmare process of creating 301 redirects to account for the change.

Even with 301 redirects though you don’t address the issue you have with applications like Disqus that require the url structure per the default configuration. They have a process, but its more involved and I was feeling exceptionally lazy.

I wanted to modify the permalink structure within Ghost so as to have a seamless transition.

It’s in the Database!

For the life of me I couldn’t figure it out. I searched online, but as you might expect with a relatively young platform guidance can be hard to come by. There were a number of hacks. Modify core, do this, do that.. yet everyone and no one seemed to know the answer — at least it wasn’t shared. Turns out, it’s all in the database!

Specifically, it’s in the settings table, ID 13, you’ll see it set to: /:year/:month/:day/:slug

How To Update Settings Table

It might feel a bit daunting at first, but it’s very quick and painless to set it so that you set up the correct permalink structure. The good news is that once you’re live, it’s not like it’s something you configure and modify daily.

My mission: change /year/month/day/post to /year/month/post.

Reminder: I had to do this because of how my previous posts/pages had been indexed by Google and other search engines. The last thing I wanted was a series of 404’s or a long list of 301’s.

1. Navigate to the database. The default configuration of Ghost use Sqlite so it’s a bit different than MySql. You’re going to need to attach the database first:

`[root@server ~]# sqlite3 /[path to install]/content/data/ghost.db`

2. Next you might want to list out the tables to understand what tables are available:

`sqlite> .tables`

It will look like this on a clean install:

3. Familiarize yourself with how to look at the database in terminal. You could configure a GUI but that sounds complicated, so here is what to do:

`sqlite> .show`

It will look like this:

4. You’re going to want to configure the databse output to look like something that makes sense (so that your eyes can easily understand what it’s showing).

Focus on:

> **headers | mode | width**

You can use these options:

`sqlite> .headers on`

`sqlite> .mode column`

`sqlite> .width 10 25 25`

5. Now output the ID | KEY | Value columns:

`sqlite> select id, key, value from settings;`

This will output something like the following:

6. Now it’s time to update ID 13 with the right permalink structure.

`UPDATE SETTINGS SET VALUE = '/:year/:month/:slug' WHERE ID=13;`

If you look at your table now it’ll look like this:

6. Now you have to be sure to restart your Ghost instance, if you followed my instructions then you can use pm2 to restart your instance:

Exit the databse:

`sqlite> .exit`

And restart the Ghost instance:

`[root@server ~]# pm2 restart Ghost`

Depending on the number of instances you have running it’ll look something like:

Congrats, now you’re all situated. As long as you retain the same domain, there shouldn’t be any issues when you go live and your permalinks should all align nicely.

Happy blogging!