Skip to content

Instantly share code, notes, and snippets.

@da2x
Created September 28, 2017 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save da2x/49f19850480a042eefff2417fd854cb5 to your computer and use it in GitHub Desktop.
Save da2x/49f19850480a042eefff2417fd854cb5 to your computer and use it in GitHub Desktop.
Redirect AMP pages to the canonical HTML equivalent.
if (document.querySelector("html[amp],html[⚡]")) {
var amp = document.head.querySelector("link[rel='amphtml'][href]"),
canon = document.head.querySelector("link[rel='canonical'][href^='https://'],\
link[rel='canonical'][href^='http://']");
if (null != canon && amp != canon) {
document.location = canon.href;
} }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment