Add RESTful Type Routes Using Apache Configuration
The root of the site http://example.com
correctly identifies index.html and renders it. In a similar manner, I want, http://example.com/foo
to fetch foo.html
present in the root of the directory.
You need to let your web server know that you want those files served when a URL is called with the file’s basename (and no extension).
If your site is served via an Apache web server you can enable the MultiViews
option. In most cases, you can do that be creating an .htaccess
file at your site root with the following line:
Options +MultiViews
With this option 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 setup to allow the option to be set in the htaccess file. If not, you would need to do it in the Apache config file itself. If your site is hosted on another web server, you’ll need to look for an equivalent setting.
In Jekyll
It could work in the above manner but it is even easier using permalink
property.
This feature is actually available in Jekyll. Just add the following line to your config.yml: permalink: pretty
This will enable links to posts and pages without .html extension,
e.g.
/about/
instead of /about.html
/YYYY/MM/DD/my-first-post/
instead of YYYY-MM-DD-my-first-post.html