<?php
function canlink() {
echo '<link rel="canonical" href="http://' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] . '" />';
}
?>
Refactorings
No refactoring yet !
Bryan Hadaway
May 30, 2010, May 30, 2010 14:14, permalink
Okay, I've worked out the code that does exactly what I want (see below). But I need help refactoring it to adapt to the syntax of my code above. Thanks
<link rel="canonical" href="http://<?php echo $_SERVER["HTTP_HOST"] ?><?php echo parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH); ?>†/>
Bryan Hadaway
June 7, 2010, June 07, 2010 08:20, permalink
Full solution here: http://www.bryanhadaway.com/super-simple-dynamic-canonical-link-code/
Take a look at what I've written so far. In the way I'm using this it almost works perfect in all scenarios even removing hash # and everything after, but I have run into query strings.
I need one version that removes just & and everything after and another that removes ? and everything after, I've been looking for a clean minimalist solution for the past 2-3 days with nothing close.
Thanks, Bryan