GitHub Pages redirection


  1. Install the jekyll-redirect-from plugin
  2. update the front matter on posts to include redirect_to:
  3. Load a post and observe the browser redirect to the new location 👍

Problem statement

I was using GitHub Pages (Jekyll) for blogging, but recently switched to WordPress. I didn’t want to break old links, so I needed a way to permanently redirect.

An SO answer got me thinking about a meta tag. Is there an efficient way to add this meta tag to posts? Yes. Some old GitHub Enterprise Pages docs recommend using the jekyll-redirect-from plugin. We can confirm it’s supported for non-Enterprise Pages by looking at the list of supported plugins. And I see it works via a meta tag.

Is the redirect permanent? Sort of. The HTTP response from GitHub is 200, but the HTML redirect includes a canonical link, eg:

$ curl -v
< HTTP/2 200 
< server:
< content-type: text/html; charset=utf-8
<!DOCTYPE html>
<html lang="en-US">
  <meta charset="utf-8">
  <link rel="canonical" href="">
  <meta http-equiv="refresh" content="0; url=">
  <meta name="robots" content="noindex">
  <a href="">Click here if you are not redirected.</a>

That script tag looks broken, but it’s shorthand for `window.location.href`.