Skip to content

Instantly share code, notes, and snippets.

@nocodesupplyco
Created February 28, 2023 20:27
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 nocodesupplyco/96c7915e631e741f8e8c6bad036bcece to your computer and use it in GitHub Desktop.
Save nocodesupplyco/96c7915e631e741f8e8c6bad036bcece to your computer and use it in GitHub Desktop.
Detect and Don't Redirect Search Bots
// 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