How can the $_SERVER['REQUEST_URI'] be trimmed to avoid multiple versions in Google's index?

To avoid multiple versions of a URL being indexed by Google, you can trim the $_SERVER['REQUEST_URI'] to remove any unnecessary query parameters or trailing slashes. This will ensure that only the canonical version of the URL is indexed by search engines.

$uri = strtok($_SERVER['REQUEST_URI'], '?');
$uri = rtrim($uri, '/');