How can the "parse_url()" function be used to check the current URL and redirect users based on the URL?

To check the current URL and redirect users based on it, you can use the "parse_url()" function in PHP to extract the URL components such as the hostname, path, query parameters, etc. Once you have the necessary information, you can use conditional statements to determine if a redirect is needed based on the extracted URL components.

$current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$url_components = parse_url($current_url);

if($url_components['path'] == "/example-page") {
    header("Location: http://example.com/new-page");
    exit();
}