What are the potential security risks of using URL masking or redirection in PHP to maintain two pages with the same content?

Using URL masking or redirection in PHP to maintain two pages with the same content can create security risks such as duplicate content penalties from search engines, potential for phishing attacks, and confusion for users. To solve this issue, you can use canonical URLs to indicate the preferred version of the page and avoid duplicate content penalties.

<?php
// Redirect to the canonical URL
$canonical_url = "https://www.example.com/canonical-page";
if ($_SERVER['REQUEST_URI'] !== "/canonical-page") {
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: $canonical_url");
    exit();
}
?>