19

I want to create a homepage and, for now, I think Github's pages features will serve my needs. However, I might want to switch to a more full-blown CMS/blog engine later on.

Is it possible to serve a permanent redirect (HTTP 301) from Github pages in case I decide to move my homepage someplace else while preserving all the old URIs?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Fred Foo
  • 355,277
  • 75
  • 744
  • 836
  • You may want to +1 this feature over at the Github support forum. – samplebias Mar 14 '11 at 18:27
  • 2
    I can't find this feature request on github. – James Ward Jan 20 '12 at 14:33
  • Do you want to mass redirect as `you.github.io/some/path` to `new_domain.com/some/path`? Or only individual redirects? I propose we keep this for mass redirect since individual redirects are covered at: http://stackoverflow.com/questions/10178304/what-is-the-best-approach-for-redirection-of-old-pages-in-jekyll-and-github-page and http://stackoverflow.com/questions/9276817/301-redirect-for-site-hosted-at-github?lq=1 – Ciro Santilli OurBigBook.com Apr 26 '16 at 14:52

4 Answers4

6

Best I can deduce is that Github has not yet added this. See Tekkub response from April 2010 re: adding it to the feature request list. Another message from another user in January suggests a META tag as a workaround (probably not a good solution).

samplebias
  • 37,113
  • 6
  • 107
  • 103
  • Ah yes, closed because it's now "on The List" -- where have I seen that one before? The `meta` workaround is ugly, but if it's good enough to fool Google, I might give it a try. – Fred Foo Mar 14 '11 at 18:35
  • both links are broken.. any chances of restoring those? – YakovL Nov 08 '21 at 20:32
1

Mass redirect layout technique

Individual page redirects are covered at: https://stackoverflow.com/a/36846720/895245 Actual 301s seem impossible.

If you want to mass redirect:

http://you.github.io/some/path

to:

http://new_domain.com/some/path

do as follows.

Before you move away

  • _layouts/default.html: the default layout

  • _config uses the default layout:

    defaults:
      -
        scope:
          path: ''
        values:
          layout: 'default'
    

After you move away

  • create _layouts/redirect.html with an HTML redirect derived from Redirect from an HTML page along:

    {% assign redir_to = site.new_domain | append: page.url %}
    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <title>Redirecting...</title>
      <link rel="canonical" href="{{ redir_to }}"/>
      <meta http-equiv="refresh" content="0;url={{ redir_to }}" />
    </head>
    <body>
      <h1>Redirecting...</h1>
      <a href="{{ redir_to }}">Click here if you are not redirected.<a>
      <script>location='{{ redir_to }}'</script>
    </body>
    </html>
    
  • _config contains:

    defaults:
      -
        scope:
          path: ''
        values:
          layout: 'redirect'
    new_domain: 'http://new-domain.com/some/path
    
  • replace every non-default layout with a symlink to the redirect layout. This is the only ugly part of this technique. I don't see a beautiful non-plugin solution.

Community
  • 1
  • 1
Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
1

For the security of their users, GitHub Pages does not support customer server configuration files such as .htaccess or .conf. However, using the Jekyll Redirect From plugin, you can automatically redirect visitors to the updated URL.

More info can be found here: https://help.github.com/articles/redirects-on-github-pages/

Mr. Hugo
  • 11,887
  • 3
  • 42
  • 60
1

Yes, it is. Shortly, set up CNAME redirection by setting a custom domain on your GitHub Pages settings.

This is usually the case when you want your GitHub Pages to be served through a custom domain (let's say the user tries to access https://kamarada.github.io/, then the browser redirects to https://linuxkamarada.com/, but the pages are indeed on GitHub).

But it also works in the case when you previously had your website served by GitHub Pages and moved to another server, e.g. GitLab Pages (I imagine that could work for e.g. WordPress as well).

See this answer: the user tries to access https://kamarada.github.io/, then the browser redirects to https://linuxkamarada.com/, but the pages are actually on GitLab.

Antônio Medeiros
  • 3,068
  • 1
  • 27
  • 22