How can a PHP script be used to redirect users based on the URL entered?

To redirect users based on the URL entered, you can use PHP's header function to send a raw HTTP header to the browser, which will redirect the user to the specified URL. You can check the current URL using $_SERVER['REQUEST_URI'] and then use conditional statements to determine where to redirect the user.

<?php
$current_url = $_SERVER['REQUEST_URI'];

if ($current_url == '/old-page') {
    header('Location: /new-page');
    exit();
} elseif ($current_url == '/another-old-page') {
    header('Location: /another-new-page');
    exit();
} else {
    // Redirect to a default page if no match is found
    header('Location: /default-page');
    exit();
}
?>