Return to site

Github pages redirect

broken image

For example, going from /oldurl.html to /newurl.html. Let’s say you have a repository with a gh-pages branch (or equivalent publishing branch) and you want to move/rename a page within that branch. So what do you do when you want to move some URLs around when using GitHub Pages? Here are the options I found.

broken image

By design, you’re not allowed to send any web server directives such as custom HTTP headers, so the 301 redirect option is out. Where this can fall down is when using static site hosting such as GitHub Pages or Surge.sh. This has the benefit that search engines will see the 301 header and automatically update their caches to reference the new URL. The best way to redirect old pages is to get the web server to send a 301 Moved Permanently HTTP header. Let’s try not to make the problem of link rot even worse. It’s a terrible experience to bookmark a page or follow a link from another site, only to find that the page has completely vanished.

broken image

That is, even if pages get moved around, or a site is completely revamped, the old URLs should still redirect somewhere. One of the golden rules I try to follow in web development is “don’t break URLs”.

broken image