Skip to content

Instantly share code, notes, and snippets.

@iMattPro
iMattPro / redirect.js
Last active June 24, 2020 19:34
301 style htaccess redirects in Javascript for GitHub Pages
/**
* 301 style htaccess redirects in Javascript for GitHub Pages.
*
* This simple script can be used on GitHub Pages hosted sites to handle redirects you would normally have used
* htaccess for. In this case, a 301 redirects from an old URL path to the new URL location. Note that this does
* not actually send 301 headers. GitHub Pages will still send a 404 header, so this is not an SEO or search
* engine solution, but without access to GitHub's server config, this will at least send your visitors to the
* correct page when browsing.
*
* Usage: Include this script inside your GitHub Pages 404.html page.