What are the potential pitfalls of using mod_rewrite in PHP scripts for URL redirection?

One potential pitfall of using mod_rewrite in PHP scripts for URL redirection is that it can lead to duplicate content issues if not properly configured. To avoid this, make sure to use canonical URLs to specify the preferred version of the URL for search engines.

// Redirect to canonical URL using mod_rewrite
if ($_SERVER['REQUEST_URI'] == '/old-url') {
    header('HTTP/1.1 301 Moved Permanently');
    header('Location: https://www.example.com/new-url');
    exit();
}