Search code examples
phphtmlseocanonical-link

Automatic canonical tag if GET parameters defined


I was doing some research into page duplicate content for dynamic keyword insertion via a GET parameter if definded, if not it will default to a definded value.

Would it be a benefit to set up a quick PHP check in the page head where by if a GET parameter is present it will automatically insert a canonical tag with the GET parameters stripped out?

Will this solve the issue of duplicate content for the page(s)?

It's worth mentioning the dynamic GET parameters will only be present when passed by ad networks such as AdWords.


Solution

  • Your idea is certainly possible, but there is an even better solution: always provide the canonical URL, even if it’s self-referential.

    <!-- on                     http://example.com/posts/1 -->
    <link rel="canonical" href="http://example.com/posts/1">
    
    <!-- on                     http://example.com/posts/1?tracking=123 -->
    <link rel="canonical" href="http://example.com/posts/1">
    
    <!-- on                     http://example.com/posts//////1?a-URL-you-never-expected -->
    <link rel="canonical" href="http://example.com/posts/1">
    

    Benefits:

    • Covers all cases of URL variants, not just the expected parameters.
    • No PHP check needed.
    • Consumers that directly land on your canonical variant can be sure that it’s the canonical URL, thanks to the explicit markup.