Skip to content

Instantly share code, notes, and snippets.

@evandrocoan
Forked from lazysod/canonical.php
Last active April 24, 2022 23:35
Show Gist options
  • Save evandrocoan/e3e6d8024420339863f2dae2751f67c9 to your computer and use it in GitHub Desktop.
Save evandrocoan/e3e6d8024420339863f2dae2751f67c9 to your computer and use it in GitHub Desktop.
Generate a canonical URL using PHP
<?php
$url = "http://domainname.com{$_SERVER['SCRIPT_NAME']}";
echo "<link rel='canonical' href=$url>";
?>
@evandrocoan
Copy link
Author

evandrocoan commented Jul 13, 2018

-->

<link rel="canonical" href="http://domainname.com/index.php">
  1. https://www.webmasterworld.com/php/4404755.htm - Canonical link with PHP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment