How to add RESTful routes to Jekyll

The root of the site http://example.com correctly identifies index.html and displays it. Similarly, I want http://example.com/foo to get foo.html in the root of the directory. A site that uses this functionality is www.zachholman.com . I saw his code in Github. But still I can not find how to do it. Please, help.

+7
source share
2 answers

In fact, the server needs to be configured, not jekyll. By default, jekyll is going to create files with the .html extensions. It may be so, but it is unlikely that you really want to go that route. Instead, you need to tell the web server that you want these files to serve when calling the URL with the base file name (and without the extension).

If your site is served through the Apache web server, you can enable the "MultiViews" option. In most cases, you can create a .htaccess file in the root of your site with the following line:

Options +MultiViews 

If this option is enabled, when Apache receives a request for:

 http://example.com/foo 

It will serve the file:

 /foo.html 

Note that the Apache server must be configured so that the option is installed in the htaccess file. If not, you will need to do this in the Apache configuration file itself. If your site is hosted on a different web server, you need to find an equivalent setting.

+2
source

This feature is available in Jekyll. Just add the following line to your _config.yml:

 permalink: pretty 

This will allow you to link to posts and pages without the .html extension, for example.

  • /about/ instead of /about.html
  • /YYYY/MM/DD/my-first-post/ instead of YYYY-MM-DD-my-first-post.html

However, you lose the ability to customize permalinks ... and the end slash is pretty ugly.

Edit: The end slash seems to be there design

+11
source

All Articles