4

Redirecting GitHub pages after a repository move

 1 year ago
source link: https://gist.github.com/domenic/1f286d415559b56d725bee51a62c24a7
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Redirecting GitHub Pages after a repository move

The problem

You have a repository, call it alice/repo. You would like to transfer it to the user bob, so it will become bob/repo.

However, you make heavy use of the GitHub Pages feature, so that people are often accessing https://alice.github.io/repo/. GitHub will helpfully redirect all of your repository stuff hosted on github.com after the move, but will not redirect the GitHub Pages hosted on github.io.

The solution

We solve this by:

  1. Moving the repository, thus breaking all the links
  2. Creating a new user GitHub Pages site for Alice (not project GitHub pages site), at https://alice.github.io.
  3. Adding a file repo/index.html to the user GitHub pages site, which uses <meta http-equiv="refresh"> to redirect to the new URL.

This means that https://alice.github.io/repo/ still exists as a working URL, even though the alice/repo repository does not. And it will redirect to the new URL, at https://bob.github.io/repo/.

The details

To create a new user GitHub pages site for Alice, Alice will just create a new repository on GitHub named alice.github.io, with a single branch gh-pages. This should work out of the box, although if it doesn't, Alice can check the settings tab for that repository to make sure it's publishing to GitHub Pages.

The file at repo/index.html in the alice/alice.github.io repository should look like this:

<!DOCTYPE html>
<meta charset="utf-8">
<title>Redirecting to https://bob.github.io/repo/</title>
<meta http-equiv="refresh" content="0; URL=https://bob.github.io/repo/">
<link rel="canonical" href="https://bob.github.io/repo/">

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK