Search code examples
githubhttp-redirectgithub-pages

GitHub Pages: redirect the old project URL to the new one


Suppose I have a project project-old, that uses GitHubPages and I created a brand new version of it: project-new..

Now, the project-new is tested and ready to "production", is there a way before archiving the project-old, located at the page
https://example.com/project-old

to redirect the visitors to the

https://example.com/project-new


Solution

  • Not easily, considering any automatic redirection is done by GitHub only when you rename a project.

    ... Except for PAges:

    When you rename a repository, all existing information, with the exception of project site URLs, is automatically redirected to the new name

    If you plan to rename a repository that has a GitHub Pages site, we recommend using a custom domain for your site. This ensures that the site's URL isn't impacted by renaming the repository

    In your case, referring to the pages of your old or new project through a custom domain would be easier.

    You can then go on and make later a new-new project, without having to worry about URL changes.


    If this is not convenient, then see "Setup a redirect on Github Pages " from Steve Belovarich, using an index.html (in your old project) with a redirect instruction.

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