Category url; have it only answer to 1 category

Here’s how I did to fix it. Added this to my functions.php

$url = $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
if($_SERVER['HTTPS']){
    $url="https://".$url;
}else{
    $url="http://".$url;
}
$id =  url_to_postid( $url );
$url = parse_url($url,PHP_URL_PATH);
$canonical = parse_url(wp_get_canonical_url($id),PHP_URL_PATH);
if($url != $canonical){
    wp_redirect(wp_get_canonical_url($id),302);
}

Basically if I hit an url that is not its own canonical, force a redirect.

@Tom J Nowell, weird but noted. Its an old website with a bunch of plugins I don’t know in detail, so I guess one of them is the culprit. Just didn’t take the time to investigate that part.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)