Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permanent redirect from Github gh-pages

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?

like image 667
Fred Foo Avatar asked Mar 14 '11 18:03

Fred Foo


People also ask

Is 302 permanent redirect?

What is a 302 redirect? Whereas a 301 redirect is a permanent relocation of your URL, a 302 redirect is a temporary change that redirects both users and search engines to the desired new location for a limited amount of time, until the redirect is removed.


2 Answers

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).

like image 122
samplebias Avatar answered Oct 17 '22 01:10

samplebias


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.