Are there any potential pitfalls to be aware of when setting up automatic URL redirection in PHP?

One potential pitfall to be aware of when setting up automatic URL redirection in PHP is the risk of creating an infinite loop if the redirect logic is not properly implemented. To avoid this, it's important to include a condition to check if the current URL is the same as the target URL before performing the redirection.

// Check if the current URL is the same as the target URL before redirecting
$current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$target_url = "http://example.com/new-page";

if ($current_url != $target_url) {
    header("Location: $target_url");
    exit;
}