What is the purpose of using canonical URLs in PHP websites and how can they help with SEO?
Canonical URLs in PHP websites are used to address duplicate content issues by specifying the preferred version of a webpage. This helps search engines understand which URL should be indexed and displayed in search results, ultimately improving SEO by consolidating link equity and avoiding penalties for duplicate content.
<?php
// Set canonical URL in PHP
$canonical_url = "https://www.example.com/page";
// Output canonical link tag in the webpage header
echo '<link rel="canonical" href="' . $canonical_url . '" />';
?>