Jekyll 301 Redirects on Netlify
This site is built with Jekyll and hosted on Netlify. Recently I needed to implement redirects for my posts on installing Python on Mac, Windows, or Chromebook which now live over at installpython3.com.
Per the Netlify docs, there are two methods available: create a
_redirects file or a
netlify.toml file. The former is simpler and worked just fine in my case where I wanted a 301 redirect, the default, since the move was permanent and SEO would be maintained as much as possible.
There are two steps required: create the
_redirects file and then add it to the existing
Step 1: Create _redirects file
This involved creating a file called
_redirects in my project root that contained the URL of a post on this site and then the redirect post it should be sent to separated by whitespace. So for my 3 posts, here’s what the file looks like.
install-python3-mac/ https://installpython3.com/mac/ install-python3-windows/ https://installpython3.com/windows/ install-python3-chromebook/ https://installpython3.com/chromebook/
This one is easy to miss! The existing
_config.yml file used by Jekyll needs to be updated to include
_redirects. So at the bottom of
_config.yml add the following line:
And that’s it! Deploy your site to Netlify per usual and then check that the link redirects properly. There are a number of tools to do this but I found this one worked well.