How to redirect Github Pages

When you change your Github username, you are greeted with the following warning (emphasis by me):

  • We will not set up redirects for your old profile page.
  • We will not set up redirects for Pages sites.
  • We will create redirects for your repositories (web and git access).
  • Renaming may take a few minutes to complete.

Since there are quite a few websites on the internet linking to pages of my blog, I needed to setup some redirection manually. To do this, I registered a new Github user with my old username Simmesimme and created a repository for the Github pages of that new user. Here are the two repositories:

When you look at those, you can see that the first repository which will be published to my previous URL ( contains an html file for each page which existed when I changed my user name. These html files simply redirect to their new location at

As there are quite a lot of html files to create, I set up a simple shell script to do this job for me. If you are in a similar situation, this may help you as well!

The Shell Script & the HTML Template

Let’s assume that you have the two repositories cloned next to each other. Let’s call them ( in my case) and ( in my case). First create a script called and a file in In the template you need to insert four times your URL.


# This script can be used to create a redirection copy of your
# website! It copies a directory structure containing html files from
# $INPUT_DIR to $OUTPUT_DIR. For each html file in $INPUT_DIR, a copy
# of is created in $OUTPUT_DIR. Then, all occurences
# of @FILE@ in the template are replaced with the name of the copied
# file.

# The output dir is assumed to be the location of this script.
OUTPUT_DIR="$( cd "$( dirname "$0" )" && pwd )"

# The input dir must be passed as first parameter.

find $INPUT_DIR -name "*.html" -printf "%P\n" | while read file; do
    mkdir -p $(dirname $file)
    cp $file
    sed -i -e "s~@FILE@~$file~g" $file
<!DOCTYPE html>

  <meta charset="utf8">
  <meta http-equiv="refresh" 
        content="0; url=">
  <link rel="canonical" href="">
  <title>This page has moved</title>

    This page has moved. Redirecting you to 
    <a href="">


Then you can execute the script. As an argument you give the path to the jekyll-generated _site directory of your repository.

chmod +x
./ ../

That’s it! Now you have set-up a redirection page for each html file!


blog comments powered by Disqus