if you have a hand coded site to help with your SEO you need a canonical link.
Below is a PHP script that creates a canonical url link on page load.
So this should answer your question of how to add canonical tag in PHP
This is a self-referencing canonical link
1 2 3 4 5 6 7 8 9 |
<?php $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; $canon = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; echo '<link rel="canonical" href="'.$canon.'">'; ?> |