foreach ($ulink->data as $val){ $string1 = URLpage; $string2 = '/url/'.$val->data['Id']; if ($string1 !== $string2){ header("Location: https://{$_SERVER['SERVER_NAME']}$string2"); } }