A Jekyll layout that redirects to a new page without using jekyll-redirect-from
plugin.
For some Jekyll sites, setting up URL re-writes or HTTP 301 Moved Permanently response codes on HTTP web servers (such as Apache or NGINX) is not possible. If you reorganise your site, external links to your original pages will be broken, which is not a great web experience.
The redirect layout creates an HTML redirection page from the original page URL to its new location.
- Copy the
_layouts/redirection.html
file to your Jekyll_layouts
folder. - Optionally create a
_redirects
folder, adding it to theinclude:
section of your_config.yml
. - Create a page with the front matter below. The redirect file name is not important as the original and redirect page URLs are controlled by
permalink
andredirect
front matter settings.
---
layout: redirection
permalink: /path/to/original/page/
redirect: /path/to/correct/page/
---
NB: The layout has been renamed from redirect.html
to redirection.html
to avoid interference with jekyll-redirect-from plugin.