Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • John Duffy 3 posts 23 karma points
    Jul 24, 2018 @ 12:15
    John Duffy
    0

    Automatically create rel=canonical for each page when it is published

    Hi

    I'm trying to find out if there's a way to automatically publish a rel=canonical tag for each page in our web sites? Currently we're asking clients to do this manually, but they are busy and forget - it's understandable.

    Feels like it's such an obvious requirement for SEO that there must be a straightforward way to do it without the web editor needing to do anything except publish their page?

    Thanks, John

  • Marc Love (uSkinned.net) 447 posts 1789 karma points
    Jul 24, 2018 @ 12:21
    Marc Love (uSkinned.net)
    2

    Place the following in the head section of the Master Template for your pages.

    @{
    var canonical = Request.Url.Scheme + "://" + Request.Url.Host + Model.Content.Url;
    }
    
    
    <link rel="canonical" href="@canonical"/>
    
  • John Duffy 3 posts 23 karma points
    Jul 24, 2018 @ 12:56
    John Duffy
    0

    Thanks Marc, we'll have a bash with that, much appreciated! jd

  • George Hajjar 1 post 71 karma points
    Feb 28, 2019 @ 03:36
    George Hajjar
    0

    Hi Marc,

    That works like a Charm. Thank you!

    The only issue I have now is that my homepage is showing with a trailing "/home" in my head.

    How can I exclude Model.Content.Url if it = "/home"

  • Marc Love (uSkinned.net) 447 posts 1789 karma points
    Jul 24, 2018 @ 13:10
    Marc Love (uSkinned.net)
    2

    For this to work you need to make sure that your website can only be served via a single domain.

    For example if you have website.com and website.org both pointing to your site you want to make sure that your site is always served via website.com

    If someone visits website.org you should redirect to website.com

    The following guide explains how to set this up via the web.config file located at the route level of your website:

    https://uskinned.net/blog/posts/2017/june/quick-tip-assign-multiple-hostnames-to-the-one-production-domain-correctly/

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Feb 28, 2019 @ 08:24
    Richard Soeteman
    0

    Might not be the answer you are looking for, but SEOChecker does this automagically. Specify domain name in seochecker settings and use the SEOChecker API to generate all the metatags at once with two lines of code.

    https://soetemansoftware.nl/seo-checker

    Best,

    Richard

  • Yakov Lebski 591 posts 2346 karma points
    Mar 02, 2019 @ 20:17
    Yakov Lebski
    1

    You can use also Umbraco built in option

     var canonicalUrl = Model.Content.UrlWithDomain();
    
     <link rel="canonical" href="@canonicalUrl" itemprop="url" />
    
Please Sign in or register to post replies

Write your reply to:

Draft