Redirects in Jekyll
So, a friend told me:
Runar, your site has a 404.
How can that be I thought? I haven’t redesigned in a while, and the couple of pages I’ve moved have valid redirects. The URL in question was https://hjerpbakk.com/fermicontainer/, so I clicked the link to prove him wrong, reveling in my future success, and got this:
As it happens, the link should point to one of the pages I’ve moved.
Redirect pages in Jekyll
As experienced readers know, this blog is written using Jekyll. I use the jekyll-redirect-from gem to easily redirect pages specified in the front matter of the new page:
redirect_from: - /fermicontainer
The eagle-eyed of you will spot the error and my ignorance: where is the redirect for
/fermicontainer/? URLs with and without a trailing
/ are not the same!
An URL with a trailing slash indicates a folder, whereas one without indicated a file. Given an URL with a trailing slash and an
index.html at that location, both URLs appears the same to the user and the browser will figure it out. That’s why I haven’t given this issue a lot of thought before.
The documentation for the jekyll-redirect-from is pretty clear on this:
Redirects including a trailing slash will generate a corresponding subdirectory containing an index.html, while redirects without a trailing slash will generate a corresponding filename without an extension, and without a subdirectory.
Thus, the solution for me was to add another redirect:
redirect_from: - /fermicontainer/ - /fermicontainer
The web is hard.