Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tjhole/9971931 to your computer and use it in GitHub Desktop.
Save tjhole/9971931 to your computer and use it in GitHub Desktop.
WORDPRESS: Redirect based on location using Cloudflare
<?php
// Geo Redirect using Cloudflare
$activepage = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$country_code = $_SERVER["HTTP_CF_IPCOUNTRY"];
$page_from = "www.domain.tld/";
$page_to = "www.newdomain.tld/";
?>
<!-- Country Code : <?php echo $country_code; ?> -->
<!-- Active URL : <?php echo $activepage; ?> -->
<?php
if($activepage == $page_from && $country_code=="US") {
Header("Location: $page_to");
die();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment