Created
January 21, 2015 10:25
-
-
Save richjenks/57cdb74e87c4637591b1 to your computer and use it in GitHub Desktop.
Redirect to canonical
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("link[rel='canonical']")) { | |
// Get current URL | |
var url = document.URL; | |
// If query string, get it and append to current URL | |
if (location.search) { | |
var query = location.search; | |
} else { | |
var query = ''; | |
} | |
// Get canonical URL | |
var canonical = document.querySelector("link[rel='canonical']").href; | |
if (url !== canonical + query) { | |
window.location.replace(canonical + query); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you for this :)
I think this
Should be