How to set up redirects in a Jekyll Blog hosted on Netlify

If you have your Jekyll site hosted on Netlify and you need to add redirects, here how.

  1. In the root add a file called “_redirects”.

  2. In this file add each redirect rule in its own line. The format is as follows

    /remove-first-character-javascript /remove-first-char 301

    Where the first path is the original one, the second one is the new one, and then optionally you can add a redirect option. 301 is the default, so I didn’t have to add it.

  3. Since we have a Jekyll blog, we need to specify in the config file that we don’t want to exclude the _redirects file (Jekyll would exclude it from the published built by default since it starts with a “_”).

    Open up your “_config.yml” (create one if you don’t have in the root) and add the following line:

        - _redirects
  4. When you push to Github and you click on the deploy, in the Deploy summary it should show the following “1 redirect rule processed. All redirect rules deployed without errors.”

    Screenshot of what Netlify will show when adding a redirect

That’s how you add a redirect when using Jekyll hosted on Netlify. Step 4 confirms that it works, but of course, test it out yourself to make sure.