What are the best practices for managing redirects in PHP websites to ensure a smooth user experience?

Managing redirects in PHP websites is crucial for ensuring a smooth user experience. It is important to handle redirects properly to avoid broken links and provide users with a seamless browsing experience. One best practice is to use HTTP status codes such as 301 (permanent redirect) or 302 (temporary redirect) to indicate the type of redirect. Additionally, make sure to update any internal links or references to the old URL to the new one to prevent confusion.

// Redirect to a new URL with a 301 status code
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.com/new-page");
exit();