基于WP_Query的页面重定向

I'm using a custom query parameter in Word, named responses for some dynamic content. I've added some conditionals that redirect a user back to the root URL if the response is put in incorrectly so they can't access a blank page. What am I doing wrong here, and is there a cleaner way to do it?

functions.php:

function add_query_vars_filter($vars) { 
  $vars[] = "response"; 
  return $vars; 
}
add_action("query_vars", "add_query_vars_filter");

The code below does work, but it looks messy to me and doesn't seem very scalable for more conditionals. page.php:

$response = get_query_var('response');

if (!$response) { 
  header("Location: https://" . $_SERVER['HTTP_HOST']);
} 
if ($response == "yes" || $response == "no") { 
  header("Location: https://" . $_SERVER['HTTP_HOST']);
}

Ideally, I'd prefer to have it all in a single conditional statement, however when I write:


if (!$response || $response == "yes" || $response == "no") { 
  header("Location: https://" . $_SERVER['HTTP_HOST']); 
}

But that doesn't redirect the user back to the host when they type ?response=yes or ?response=no