以人为本

Core developer of Mixin Network. Passionate about security and privacy.

Jekyll Clean URLs with Nginx

Aug 22, 2014

Just generated the Shou.TV blog with Jekyll, I want to use a unique URL for each post like https://blog.shou.tv/the-technology-behind-shoutv, without any alternatives e.g. a .html extension, a trailing slash at the end or a trailing slash followed by index.html.

It’s easy to achieve this objective with a simple nginx rule. At first, configure the Jekyll permalink style in _config.yml

permalink: /:title

The nginx configuration rules are quite simpler than expected:

rewrite ^/index.html$ / permanent;
rewrite ^(/.+)/$ $1 permanent;
rewrite ^(/.+)/index.html$ $1 permanent;

location / {
  try_files $uri $uri/index.html =404;
}

This will redirect all other URL alternatives to the exact same URL.

Inspired by http://rickharrison.me/how-to-remove-trailing-slashes-from-jekyll-urls-using-nginx

About the Author

Core developer of Mixin Network. Passionate about security and privacy. Strive to formulate elegant code, simple design and friendly machine.

25566 @ Mixin Messenger

[email protected]