Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
redirects utah ip addresses to the utah home page
<script>
(function() {
var geoIpServiceUrl = 'https://freegeoip.net/json/';
var redirectUrl = 'http://youturn.org/ut';
var isBotSpider = Boolean(navigator.userAgent.match(/bot|spider/i));
var alreadyUtRedirected = Boolean(document.cookie.replace(/(?:(?:^|.*;\s*)utRedirected\s*\=\s*([^;]*).*$)|^.*$/, '$1'));
var atRoot = window.location.pathname === '/';
var shouldRedirect = atRoot && !alreadyUtRedirected && !isBotSpider;
function redirect(response) {
if (response.region_name == 'Utah') {
document.cookie = 'utRedirected=true';
window.location.replace(redirectUrl);
}
}
if (shouldRedirect) {
jQuery.get(geoIpServiceUrl, redirect, "jsonp");
}
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.