<?php
$uriRequest = $_SERVER['REQUEST_URI'];

if (preg_match('/\/register/i', $uriRequest)) {
    http_response_code(301);
    header('Location: https://clubhouse.skytrakgolf.com/register');
    exit();
}

if (preg_match('/\/updatepassword/i', $uriRequest)) {
    http_response_code(301);
    header('Location: https://clubhouse.skytrakgolf.com/forgot-password');
    exit();
}

if (preg_match('/\/forgotpassword/i', $uriRequest)) {
    http_response_code(301);
    header('Location: https://clubhouse.skytrakgolf.com/change-password');
    exit();
}

$headers = apache_request_headers();
$userAgent = trim($headers['user-agent'] ?? ($headers['User-Agent'] ?? ''));
$isIgnore = false;
$aIgnore = [
    'Unity'
];
foreach ($aIgnore as $keyIgnore) {
    if (preg_match("/$keyIgnore/i", $userAgent)) {
        $isIgnore = true;
        break;
    }
}

if (!strlen($userAgent) || $isIgnore) {
    http_response_code(200);
    echo 'it is fine.';
    exit();
}

http_response_code(301);
header('Location: https://skytrakgolf.com');
exit();

