phphttpurlcanonical-link

How to get/read the cleanest url into Meta Canonical via PHP?


Given: URLs like /somepage?ln=en are rewritten in htaccess to /en/somepage
Given: used canonical Meta tag, with this PHP script above it to fill in the tidy URL:

How to make them like the canonical?

<link rel="canonical" href="<?=$canonicalURL?>">

What ways can one parse the current URL without any strings, or, delete the extra strings from the curl and put it into the canonical URL?


Solution

  • Essentially, you just want to get rid of the query string from $extensions, correct?

    <?php
    $qsIndex = strpos($extensions, '?');
    $extensions = $qsIndex !== FALSE ? substr($extensions, 0, $qsIndex) : $extensions;