php如何只允许url中的特殊参数或重定向到其他参数

I need help to write function which help me clean out any unusual ( not allow in array list) then redirect to right url

eg my original is /modules.php?aaa=111&bbb=2

the var aaa and bbb is alow using on urls ,

if some one ads other var to url incase you mess up or want to overhead the server they will redirect back to original one.. but cut all invalid param out.

eg: /modules.php?aaa=111&notgood=999&bbb=2

will redirect back to

modules.php?aaa=111&bbb=2

the &notgood=999 or any other will be strip out..

$goodvar = array("aaa","bbb");
$requesturi = $_SERVER['REQUEST_URI'];

if   /// Need help : if other query not in the list of good var will be clean out of requesturi to build NEWrequesturi
{
    header("Location: ".$NEWrequesturi,TRUE,301); exit; die(); 
}

thanks very much kind regards

<?php

$good_var = ["aaa", "bbb"];
$query_params = explode(".php?", $_SERVER['REQUEST_URI'])[1];
$all_query_data = explode("&", $query_params);
$data_set = [];
foreach ($all_query_data as $query_value) {
    $param = explode("=", $query_value);
    $data_set[$param[0]] = $param[1];
}
$paased_args = array_keys($data_set);
if (empty(array_diff($paased_args, $good_var))) {
    echo "Url is good";
    // do whatever you want when url is good
} else {
    echo "Url tempered";
    //url has been tempered do as you wish
}