jekyll-netlify-redirects

jekyll-netlify-redirects

A Ruby gem for generating a Netlify redirects configuration from a Jekyll configuration.

jekyll-netlify-redirects

A Ruby gem for generating a Netlify redirects configuration from a Jekyll configuration.

Netlify's URL redirection and rewriting rules are quite powerful. Netlify provides two options for configuring your Netlify-deployed website's rules: either in a netlify.toml file or in a _redirects file.

Both file formats are perfectly serviceable, but if you're anything like me, you prefer fewer configuration files cluttering up your project. jekyll-netlify-redirects allows you to configure your Netlify-deployed website's URL redirection and rewriting rules using your project's existing Jekyll configuration file.

Getting Started

Before installing and using jekyll-netlify-redirects, you'll want to familiarize yourself with Jekyll (a fabulous static site generator written in Ruby) and Netlify (a fabulous website hosting service). In particular, you'll want to read up on Netlify's Redirect & Rewrite Rules documentation.

Installation

If you're using Bundler, add jekyll-netlify-redirects to your project's Gemfile:

source 'https://rubygems.org'

group :jekyll_plugins do
  gem 'jekyll-netlify-redirects'
end

…and hop over to your command prompt and run…

$ bundle install

Usage

With jekyll-netlify-redirects added to your project's Gemfile and installed, add the following to your Jekyll configuration file (typically _config.yml):

netlify:
  redirects:
    - /home              /
    - /blog/my-post.php  /blog/my-post
    - /news              /blog
    - /google            https://www.google.com

Note: Netlify supports a variety of redirection and rewrite rules, so comb through their Redirect & Rewrite Rules documentation for more on the syntax. You may also want to test your redirect and rewrite rules at Netlify's Playground.

With this configuration added to _config.yml (or to your custom Jekyll configuration file), Jekyll will generate a properly-formatted _redirects file in the destination directory when building your project.

Improving jekyll-netlify-redirects

Want to help make jekyll-netlify-redirects better? Hell yeah! I like your enthusiasm. For more on how you can help, check out CONTRIBUTING.md.

Donations

If diving into Ruby isn't your thing, but you'd still like to support jekyll-netlify-redirects, consider making a donation! Any amount—large or small—is greatly appreciated. As a token of my gratitude, I'll add your name to the Acknowledgments below.

Acknowledgments

jekyll-netlify-redirects wouldn't exist without the hard work of all the folks involved in designing, building, and maintaining Jekyll and Netlify. High fives, y'all. 🙌🏻

jekyll-netlify-redirects is written and maintained by Jason Garber.

License

jekyll-netlify-redirects is freely available under the MIT License. Use it, learn from it, fork it, improve it, change it, tailor it to your needs.