-
-
Save nocodesupplyco/96c7915e631e741f8e8c6bad036bcece to your computer and use it in GitHub Desktop.
Detect and Don't Redirect Search Bots
This file contains 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
// list all bots to detect | |
let crawlerAgentRegex = /bot|google|aolbuild|baidu|bing|msn|duckduckgo|teoma|slurp|yandex/i; | |
if (crawlerAgentRegex.test(navigator.userAgent)) { | |
//don't redirect the bots and do something else if needed | |
} else { | |
if (document.cookie.indexOf("gate-access=") < 0) { | |
// if user DOES NOT have "gate-access" cookie, redirect them to example.com | |
location.href = "https://example.com"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment