Created
September 28, 2017 13:47
-
-
Save da2x/49f19850480a042eefff2417fd854cb5 to your computer and use it in GitHub Desktop.
Redirect AMP pages to the canonical HTML equivalent.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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