Skip to content

Instantly share code, notes, and snippets.

@ludndev
Last active September 7, 2019 03:08
Show Gist options
  • Save ludndev/57e3e479f97b9269fb5b20801800e9ff to your computer and use it in GitHub Desktop.
Save ludndev/57e3e479f97b9269fb5b20801800e9ff to your computer and use it in GitHub Desktop.
Generate canonical url with PhP
<?php
// get the rigth protocol
$protocol = !empty($_SERVER['HTTPS']) ? 'https' : 'http';
// simply render canonical base on the current http host ( multiple host ) + requests
echo $protocol . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment