How can URL parsing be utilized in PHP to improve search engine indexing of dynamic links on a website?

Dynamic links on a website can create issues for search engine indexing as they often contain query parameters that can make the URL appear messy and less SEO-friendly. One way to improve search engine indexing of dynamic links is by using URL parsing in PHP to extract relevant information from the URL and present it in a more structured and readable format.

// Example of URL parsing in PHP to improve search engine indexing of dynamic links

// Sample dynamic URL: https://www.example.com/product.php?id=123

// Parse the URL and extract the product ID
$url = "https://www.example.com/product.php?id=123";
$url_components = parse_url($url);
parse_str($url_components['query'], $params);
$product_id = $params['id'];

// Use the extracted product ID to generate a more SEO-friendly URL
$seo_friendly_url = "https://www.example.com/product/" . $product_id;

// Redirect to the SEO-friendly URL
header("Location: $seo_friendly_url");
exit;