What is the best practice for automatically inserting the title of an article into a URL redirect in PHP?

When automatically inserting the title of an article into a URL redirect in PHP, it is best practice to sanitize the title to remove any special characters or spaces that could break the URL. One way to do this is by using the `urlencode()` function to encode the title before appending it to the redirect URL.

// Assuming $articleTitle contains the title of the article
$cleanTitle = urlencode($articleTitle);
$redirectURL = "https://example.com/article/" . $cleanTitle;
header("Location: $redirectURL");
exit();