I am running website on Jekyll. I want to make links, like contact
to contact.md
(now I am using contact.html
link) - that means I want to remove .html extension. I read this question - How to link to a page with page.url without the html extension in Jekyll?, but it tells to create directory for each folder. I do not like this idea - I want to have everything in one, main directory. Can you give my any advice?
-
Possible duplicate of [How to link to a page without html extension in Jekyll?](http://stackoverflow.com/questions/22034994/how-to-link-to-a-page-without-html-extension-in-jekyll) If such solution exists, it will be upvoted there ;-) – Ciro Santilli OurBigBook.com Apr 26 '16 at 13:16
3 Answers
That is correct. A static site always has to have a page to render. Most web servers are configured to look for index.html
if you specify a directory.
If you were using an application server, like Unicorn
, and serving dynamic then you can handle requests however you want, but web servers like Nginx and Apache will look for files on disk.
Thus:
example.com/contact.html
would actually become:
example.com/contact/index.html
But you could omit the filename, and the web server will figure it out:
example.com/contact

- 40,531
- 21
- 102
- 137
permalink is your solution.
See my answer here for short explanation.

- 1
- 1

- 51,670
- 6
- 121
- 147
You can set up permalink handling in Jekyll any way you want. First, look into Jekyll's built-in permalink support where a format of (just for example)
permalink: blah/:title
Or
permalink: /:categories/:title
will convince Jekyll to start emitting extensionless permalinks. Then to clean up the wasteful /foo/index.html
structures created by Jekyll under that scheme, use something like Will Norris's jekyll-clean-urls (or my own jekyll-simple-urls for a more primitive approach). The basic idea there is to selectively replace /foo/index.html
with /foo.html
as needed.
module Jekyll
class Post
# Obtain destination path, using clean URLs if requested.
#
# By default, Jekyll will treat /:title permalinks the same as /:title/,
# using a destination file of /:title/index.html. Instead, we change the
# destination file to /:title.html if clean URLs are requested.
def destination_with_clean_urls(dest)
path = destination_without_clean_urls(dest)
path.sub!(/\/index.html$/, '.html') if clean_urls?(permalink)
path
end
alias_method :destination_without_clean_urls, :destination
alias_method :destination, :destination_with_clean_urls
Then you can use MultiViews or a simple rewrite (or go full-hog and serve extensionless HTML files) to make sure that requests for /foo
yield /foo.html
. If you're using jekyll serve
or the connect
middleware through Yeoman you'll need to make a couple additional tweaks but that's the idea.