1

I am developing my blog in Jekyll (3.0.0 beta), currently on localhost,

When i am trying to implement the pretty permalink and i try to visit a post it shows a WEBrick error.

If i apply the /:year/:month/:day/:title.html it works fine do you have a clue why isn't it working with pretty permalinks?

This is the error I get:

/2015/08/03/are-permas-working.html' not found. WEBrick/1.3.1 (Ruby/2.1.6/2015-04-13) at localhost:4000

matrixanomaly
  • 6,627
  • 2
  • 35
  • 58
Thanos Bousis
  • 350
  • 2
  • 11
  • Please provide more information, what is the exact error when you do `permalinks: pretty` in your `_config.yml`? Not you need to restart the server when you change values in `_config.yml` – matrixanomaly Aug 03 '15 at 15:24
  • @matrixanomaly this is the error i get. Not Found `/2015/08/03/are-permas-working.html' not found. WEBrick/1.3.1 (Ruby/2.1.6/2015-04-13) at localhost:4000 – Thanos Bousis Aug 03 '15 at 15:31

1 Answers1

2

Once you set Jekyll permalinks to pretty in _config.yml like so:

permalink : pretty

... and restart your WEBrick server (a restart of the server instance using jekyll serve or bundle exec jekyll serve [if following GitHub] is needed for the new values to take effect, your permalinks will no longer be in the format of YYYY/MM/DD/title-slug.html since they are now "pretty". The new format for your links will be /:categories/:year/:month/:day/:title/. This is in accordance to the format determined by the pretty variable as defined here in the documentation.

What this means for you is that your original link for the 'Are permas working' post is no longer at localhost:4000/2015/08/03/are-permas-working.html, rather they are now at localhost:4000/2015/08/03/are-permas-working/ since you don't have a category defined.

You're experiencing this error because after you've made the change and restarted your server you most likely did not navigate to the post from your homepage (which will have that new link to point to the post), rather you just refreshed the page on your browser, which will throw a 404 since the page is no longer there.

Bonus, Jekyll makes posts pretty by creating folders 2015 -> 08 -> 03, and then a folder for that specific post, with an index.html inside it.

Also, if you wanted "pretty-fied" links that don't have the dates there, you'll need to manually specify that using this:

permalink: "/:categories/:title"

This ensure will hide the .html extension and also get rid of date values.

EDIT: From the comments I stated that using /:title for permalinks might not work since there are conflicts with non-post pages, I stand corrected. If you wanted short permalinks like user.github.io/title-of-blog-post/ you would just need to set permalink : /:title and you're good to go. However, if you have non-post pages such as an about page, a credits page, you should explicitly set permalinks on those pages to be /about and /credits on the YAML frontmatter to avoid the edge case of also having a blog post with the title about and accidentally overwriting the non-post page.

matrixanomaly
  • 6,627
  • 2
  • 35
  • 58
  • Ok this works as you said. I added a categories: post in the front matters of every post and permalink: /:categories/:title and now my url looks like this localhost:4000/post/are-my-permas-working/ what if don't want the /post to be there and i want my url to look like localhost:4000/are-my-permas-working/ i tried to add permalinks: /:title in _config.yml but it is not working. I am sorry i am new to Stack Overflow. – Thanos Bousis Aug 03 '15 at 16:51
  • 1
    @ThanosBousis that's perfectly alright, no need to be sorry. Welcome to SO! :) You can try `permalink : /:title` (not `permalinkS` as you mentioned), but I checked google and it doesn't seem to work. Your best bet is to either remove the use of categories, or manually set the permalink in every post. (just to go every blog post, at the top between the dashes add `permalink: are-my-permas-working`, but this can be annoying since you **have to do it for every post**. – matrixanomaly Aug 03 '15 at 16:57
  • @ThanosBousis sorry for the misinformation, turns out `permalink: /:title` works nicely. I just had the chance to test it out. It didn't back when I tried it, though. Updated my answer. – matrixanomaly Aug 04 '15 at 15:44
  • yes it does this is my site now [link](bousis.github.io/myblog) i have this in 'gh-pages' branch but i don't know to move it to master so i can get 'bousis.github.io' as default. Any ideas? – Thanos Bousis Aug 04 '15 at 15:50
  • @ThanosBousis sure, rename your repo from 'myblog' to `bousis.github.io`, and then you need to (after pulling down the new renamed repo), rename the branch from gh-pages to master using **`git branch -m gh-pages master`** and then **`git push -m origin master`**. refer to: http://stackoverflow.com/questions/2862590/how-to-replace-master-branch-in-git-entirely-from-another-branch – matrixanomaly Aug 04 '15 at 15:57
  • Since you mentioned you're a newbie, you can rename your repo on GitHub by following this: https://help.github.com/articles/renaming-a-repository/, after that, pull down the repo with `git pull` like how you have done before, and then rename the gh-pages branch using those 2 commands like I mentioned. :) – matrixanomaly Aug 04 '15 at 16:07
  • Everything works great as i want. Thank you. Sorry for writing answers than comments. – Thanos Bousis Aug 04 '15 at 17:44
  • @ThanosBousis glad you got it fixed. :) no problem, just wanted to give you a heads up because many users get very annoyed by this (it also get flagged a low quality and you lose rep). Take care and have fun learning on Stack Overflow! – matrixanomaly Aug 04 '15 at 20:46