Developer forum

Forum » CMS - Standard features » Canonical links

Canonical links

Kim Hansen
Reply

Hey,

Are there any way to show canonical links the way Google likes them?

Right now, DW is generating a base href and a relative canonical, like this:

<base href="https://www.domain.dk/">

<link rel="canonical" href="/products/group/product">

But Google wants the canonical with a absolute link

<link rel="canonical" href="https://www.domain.dk/products/group/product">

Thanks :)

/Kim


Replies

 
Nicolai Pedersen
Reply

Hi Kim

You cannot. Lets anticipate Google follow the html specs, they do get the absolute link: https://www.w3.org/TR/2014/REC-html5-20141028/document-metadata.html#the-base-element

base + relative = absolute. If they did not use the base tag, other ressources would also not be found by Google - i.e. css files - or link to other pages on the website.

But if it is very important we can look into it...

Also consider that if you need canonicals, you maybe want to fix the navigation structure instead so you do not have dc?

BR Nicolai

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

In my experience so far, as much as I would like to avoid Duplicate content, that almost always impossible. Customers will always want a "recommended products" group or any kind of group where they collect products from different other groups. Of course, for B2B scenarios or where the products are available behind a login, that's not so important. But for B2C it will always be important as long as Google will downrate duplicate content. And I know you have had your fair share of SEO specialists, everybody with his own "book" and "expertise" and mixed opinions about what is SEO friendly.
In all honesty, Canonical URL's have always been a pain for you and for us alike. And unfortunately it's still not right.
This post is my witness: https://doc.dynamicweb.com/forum/ecommerce-standard-features/ecommerce-standard-features/canonical-link-in-meta

Thank you,

Adrian

 
Nicolai Pedersen
 
Kim Hansen
Reply

Hi Nicolai,

Unfortunatly we live in a Google world, where we have to do as Google says, and not "the right way" :)

Google changed the way they looked at canonicals about 2 years ago from base + relative = absolute, to strictly absolute.

If you could add a checkbox (sorry) with something like "Include main domain in canonical" it would lighten our work alot.

Regarding changing the structure, its not that easy when the website is out of our hands, and in control of the customer. Of course we can recommend how they do it, but its seldom followed.

Thanks

/Kim

 
Nicolai Pedersen
Reply

Hi Kim

I understand - but do not agree that Google does not support canonicals using base href. I agree though, that their recommendation is to add domain - something they added because people does not understand the concept of canonicals - having the same page live on multiple domains with the same canonical path giving more than one url, which is wrong...

Dynamicweb handles that part using primary domain to ensure that only one domain/host can be used on a website.

Anyways, will add the option to use the primary domain if that is specified - if no primary domain is specified, I do not think we should add the domain as there could be more possible domains, hence sending wrong signals to Google. Agree?

Also today, Dynamicweb only adds the canonical if the current URL is different from the canonical. Should we change that so you can have the tag always if available? It seems to cause a lot of confusion...

BR Nicolai

 
Kim Hansen
Reply

Hi Nicolai,

Its been a bit hard to locate, but here: https://support.google.com/webmasters/answer/139066#2

in the last chapter called "Specific methods", and the paragrph called "Use rel="canonical" link tag":

Use absolute paths rather than relative paths with the rel="canonical" link element.
Use this structure:  https://www.example.com/dresses/green/greendresss.html
Not this structure: /dresses/green/greendress.html

No primary domain is specified = no domain added to canonical. I agree.

I've always been told that it should only be there if the page is a doublicate; as you do it right now.

/Kim

 
Nicolai Pedersen
Reply
This post has been marked as an answer

That is a page I frequent often - no#3 in Google when googling "canonicals", and the one I read again yesterday :-).

"Use absolute paths rather than relative paths". "Rather than" means relative works, but absolute is preferred... (Rather then - 'hellere end' in Danish). Otherwise they would write something like "Only absolute paths are supported".

Anyways - I'll give you the domain.

BR Nicolai

Votes for this answer: 1
 
Kim Hansen
Reply

Thank you :)

 
Danni Larsen
Danni Larsen
Reply

Hi Nicolai

I'm facing the same issue on one of my customers.

Can you share the solution for how to add absolute urls in canonicals?

 

BR Danni

 
Nicolai Pedersen
Reply

Hi Danni

It was added as part of the regular rendering - so if your solution is new enough, this should be there.

What version is this? Are we talking about the product detail page? And do you use the 'old' product catalog or the one for viewmodels?

BR Nicolai

 
Danni Larsen
Danni Larsen
Reply

This is DW 9.9.6 and Rapido 3.4.2

It seems to work in content pages, but not for ecommerce:

Ecommerce (NOT working/Relative canonicals): https://vvsplus.dk/shop/vand/bloedgoeringsanlaeg/bwt-aqa-life-bloedgoeringsanlaeg-4-plus-familie-398841210

Content (WORKING / Absolute canonicals): https://vvsplus.dk/kontakt-os

We're using standard Rapido templates (regarding meta tags)...

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Danni,

Have you set a Default group on the product?

Also, keep in mind that it might be possible that the canonical link would be generated only if the product is assigned to multiple Groups. I am not sure if this behavior has changed recently.

Adrian

 
Danni Larsen
Danni Larsen
Reply

Hi again

The canonical is there, as you can see it in the code.
The problem, as described, is that it's relative on product pages, and not absolute:

There's a primary group assigned, if that's what you're asking for:

 
Danni Larsen
Danni Larsen
Reply

Any news?

 
Nicolai Pedersen
Reply

Hi Danni

I have checked out your settings, and they look ok. Going from relative paths to absolute paths is relatively new, but should be on your version.

It does "work on my machine" which does not help you a lot.

You can open the master template on your installation and add a bit of code to add the domain - this is how DW does it:

string domain = Context.Current.Request.Url.DnsSafeHost;
   if (!string.IsNullOrEmpty(Dynamicweb.Frontend.PageView.Current().Area.DomainLock))
    {
                  domain = Dynamicweb.Frontend.PageView.Current().Area.DomainLock;
     }
     string absoluteCanonical = $"{(Context.Current.Request.IsSecureConnection ? "https://" : "http://")}{domain}{SearchEngineFriendlyURLs.GetFriendlyUrl(canonical)}";

Alternatively an upgrade to a later version.

BR Nicolai

 
Danni Larsen
Danni Larsen
Reply

EDIT:

Can you tell me what's inside the "canonical" variable, as it seems to miss from your code example...

The issue is that, doing the custom canonical, I would need to remake ALL the other metatags, at the "@Model.MetaTags", has all of the metatags, and I see no way of changinging / removing only the canonical from this...

So the answer is to update to latest DW version?

 
Nicolai Pedersen
Reply

Hi Danni.

In your master template you can do this hacksy thing:

@{ 

 string domain = Context.Current.Request.Url.DnsSafeHost;

 if (!string.IsNullOrEmpty(Dynamicweb.Frontend.PageView.Current().Area.DomainLock))

 {

 domain = Dynamicweb.Frontend.PageView.Current().Area.DomainLock;

 }

 string absoluteCanonical = $"{(Context.Current.Request.IsSecureConnection ? "https://" : "http://")}{domain}";


 }

 @Model.MetaTags.Replace("rel=\"canonical\" href=\"/", $"rel=\"canonical\" href=\"{absoluteCanonical}/")
 
Danni Larsen
Danni Larsen
Reply

Hi Nicolai

This is exactly what i needed 🙏

Do you know if there's an option to remove the <base> tag, or would you remove it, the same way - with a replace?

 

BR
Danni

 
Nicolai Pedersen
Reply

Great - and yes you can:

 

You must be logged in to post in the forum