Skip to content

Instantly share code, notes, and snippets.

@saibotsivad
Created October 25, 2014 21:57
Show Gist options
  • Save saibotsivad/9b4e9b76cb12d351d63d to your computer and use it in GitHub Desktop.
Save saibotsivad/9b4e9b76cb12d351d63d to your computer and use it in GitHub Desktop.

Context

Github Pages only supports redirects via Jekyll's ruby gem, which creates static HTML files with a <meta http-equiv="refresh" in the <head>.

Problem

If you run a JavaScript site that uses hash fragments (aka, site.com/#!/page) search engines may not be able to index the content. (See noddity as a blog framework that uses hash fragments but serves static files.)

General Solution

Most search engines an HTML tag <meta name="fragment" content="!"> in the <head>, which redirects to the URL and uses _escaped_fragment_ as a query parameter.

E.g., site.com/#!/page redirects to site.com/?_escaped_fragment_=/page which serves up static HTML.

Problem

Github Pages don't support .htaccess rules (for good reasons), so the _escaped_fragment_ method does not work.

Solution

???

I don't have one, but I would like to find one.

Possible Solutions?

I run a server with a LAMP stack, and use a .htaccess file to provide the redirect. You can see the file here.

Github Pages (GP) doesn't support htaccess, but maybe they would be willing to support one if it were standardized in some way?

For example, GP supports a CNAME record as a way to use your own domain to show GP content.

The important rule in the .htaccess file is this:

RewriteCond %{QUERY_STRING} ^_escaped_fragment_=(?:[^&]*/)?([^&/]*)
RewriteRule .* "http://static.site.com/?%1"

Which would redirect requests like site.com/?_escaped_fragment_=/post to static.site.com/post.

How could GP standardize this redirect so that a person could offload static generation to some other site?

@saibotsivad
Copy link
Author

Perhaps search engines would support a modification to the meta tag, something like:

<meta name="fragment" content="!" redirect="static.site.com/path/">

Which would take site.com/#!/page and look at static.site.com/path/page for the static content to index, but still point to site.com/#!/page as the link on their search results page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment