How to do redirects in Jekyll.27 May 2021
I am redoing some segments of my website – probably a bad idea – and wanted to put in place some redirects in case people have bookmarks or something like that. To my surprise, I get steady visitors to my multi-page tutorials.
This is super easy with a Jekyll plugin jekll-redirect-from!
Quick overview – read from the plugin authors for more detail though:
- add the plugin to your
- in the target file, i.e. where you want people to end up, put
redirect_from: /ts/2018_07_28/in the front matter.
Generate and you’re good to go. What happens is the plugin generates an HTML file that performs the redirect:
<!DOCTYPE html> <html lang="en-US"> <meta charset="utf-8"> <title>Redirecting…</title> <link rel="canonical" href="http://localhost:4000/ts/2018/07/27/docker-tutorial-1/"> <script>location="http://localhost:4000/ts/2018/07/27/docker-tutorial-1/"</script> <meta http-equiv="refresh" content="0; url=http://localhost:4000/ts/2018/07/27/docker-tutorial-1/"> <meta name="robots" content="noindex"> <h1>Redirecting…</h1> <a href="http://localhost:4000/ts/2018/07/27/docker-tutorial-1/">Click here if you are not redirected.</a> </html>
which you can take a look at in the