How to customize post permalinks?

Hey guys,

I continue to migrate my website to Hugo. Today I’m struggling with permalinks and need your help. Here is the URL structure that is currently used on my existing website:

(1) http://www.domain.com/categories/
(2) http://www.domain.com/category/golang/
(3) http://www.domain.com/category/golang/introduction-to-golang

(1) is a no-brainer and easy to set up with Hugo.
As for (2) and (3) – they are weird, since taxonomy name is singular (category instead of categories).
In my case, number (2) is easy to solve by creating aliases inside the front-matter (_index.md) for each taxonomy term.

The real problem is (3). On my existing website, there are facebook/twitter/G+ social buttons with hundreds of likes. Unfortunately, those social platforms do not respect 301 redirect, so if I change the structure of post urls, I’ll loose all the social counts.

In a perfect world I would like to keep old urls as they are and let Hugo build its own url structure for new posts.

Any ideas here? I also consider Nginx-based solutions.

For (2) you don’t need to create aliases. Hugo allows you to change the default permalinks in the config file_

[taxonomies]
category = "categories"

To my knowledge, (3) can’t be used to define a permalink à la www.domain.com/category/[category-name]/[slug] with the available options.

Aliases are hard to maintain. Once you change the structure of a permalink you have to update the aliases as well.

1 Like

I see a blank page (200 OK) by going to /category/golang/. What template is responsible for rendering this url?
/categories/golang/ works fine though.

By default it’s layouts/_default/list.html.

Isn’t this what tried to change with aliases?

@digitalcraftsman sorry, nvm. You are hundred percent right. Please, ignore my last comment.
I saw blank page because I had /content/category/ folder that shouldn’t exist.

Without aliases, going to /category/golang/ results to a 404. My config.yaml does have taxonomies set up.

Anyhow, this ^ is not a problem, since I can really solve it with aliases. Thanks, though.