How can the issue of indexed links with .php4 extensions be addressed when transitioning to .php extensions?

Issue: The issue of indexed links with .php4 extensions can be addressed by setting up a 301 redirect from the old .php4 URLs to the new .php URLs. This will ensure that any existing indexed links pointing to the old URLs will be redirected to the new URLs, preserving SEO value and ensuring a seamless transition for users.

<?php
if (strpos($_SERVER['REQUEST_URI'], '.php4') !== false) {
    header('HTTP/1.1 301 Moved Permanently');
    header('Location: ' . str_replace('.php4', '.php', $_SERVER['REQUEST_URI']));
    exit();
}
?>