Canonical URLS correct with CGBlog

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
wmdvanzyl
Forum Members
Forum Members
Posts: 214
Joined: Fri May 06, 2011 12:48 pm

Canonical URLS correct with CGBlog

Post by wmdvanzyl »

This is a continuation of viewtopic.php?f=7&t=76665
calguy1000 wrote:Note: for SEO purposes, you should ensure that that the articles in each category ALWAYS link to the same appropriate detail page. So that the canonical URL is always consistent.
Rolf wrote:https://www.cmscanbesimple.org/blog/bas ... d-metatags
Since i am forced to not use the slugs for detail templates, i have to get the canonical url correct. (As stated by the guru's above.)

I am seeing that i am missing a part of the url in my canonical url.

The URL is

Code: Select all

https://modh.co.za/blog/10/48/7-KEY-ASPECTS-WHEN-BUILDING-YOUR-FIRST-HOME
But my canonical URL is

Code: Select all

https://modh.co.za/blog/10/7-key-aspects-when-building-your-first-home
@Rolf, i used your website linked above as guidance (amazing help by the way). I have this in my template:

Code: Select all

<link rel="canonical" href="{$canonical_url}" />
and this in my blog detail template:

Code: Select all

{$canonical_url = $entry->canonical|lower scope=global}
TL;DR: Why is that '/48' being stripped from the canonical URL? Is this correct?
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: Canonical URLS correct with CGBlog

Post by Rolf »

This part lowers the case in the url:
{$canonical_url = $entry->canonical|lower scope=global}
Remove this and the url stays uppercase
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
wmdvanzyl
Forum Members
Forum Members
Posts: 214
Joined: Fri May 06, 2011 12:48 pm

Re: Canonical URLS correct with CGBlog

Post by wmdvanzyl »

Rolf wrote:This part lowers the case in the url:
{$canonical_url = $entry->canonical|lower scope=global}
Remove this and the url stays uppercase
Thanks, i got that. But i struggle wrapping my head around canonical URL's. If i have 10 blog posts, do they all have the same canonical URL (the blog page they are on) or should they have 10 separate canonical URL's? The latter is what i understand it to be. Canonical URL should be a valid URL that is the final/correct/only/real location for a specific piece of web content. This is so that search engines can correctly identify all the different variations that are essentially the same piece of content. That's my understanding. So every blog post should have a unique URL. The slug is great for this, but since i can't use that, i have to identify it by page id and article id. But we are only using the page id... So wouldn't every blog post then have the exact same canonical url - and that can't be right, can it?
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: Canonical URLS correct with CGBlog

Post by Rolf »

I cant see what is wrong with the provided information, but I can guarantee the method described at my blog works for 100%
https://www.cmscanbesimple.org/blog/bas ... d-metatags
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3484
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Canonical URLS correct with CGBlog

Post by velden »

The canonical url which is generated indeed differs from the url generated by CGBlog for the 'more url'. The latter contains the page id (returnid) while the canonical url is lacking that id.

I guess that's what you mean?

BTW: those canoncical urls do lead to a working page and seem to be unique per article.

Why the more-url and canonical url differ I don't know.
wmdvanzyl
Forum Members
Forum Members
Posts: 214
Joined: Fri May 06, 2011 12:48 pm

Re: Canonical URLS correct with CGBlog

Post by wmdvanzyl »

velden wrote:The canonical url which is generated indeed differs from the url generated by CGBlog for the 'more url'. The latter contains the page id (returnid) while the canonical url is lacking that id.

I guess that's what you mean?

BTW: those canoncical urls do lead to a working page and seem to be unique per article.

Why the more-url and canonical url differ I don't know.
@Rolf @velden - Thanks for the responses.

The page it directs to, however, is the default CGBlog page, so it doesn't have the correct template applied. This again comes back to the issue of pretty URL's / slugs and CGBlog. I totally get that it can't be done, i'm just trying to find a work-around. Will it matter that the article now looks wrong? Is there a way to manipulate the page id to be the one i want it to use? I am referring to this:

Code: Select all

{cge_module_hint module=CGBlog detailtemplate=sports}
wmdvanzyl
Forum Members
Forum Members
Posts: 214
Joined: Fri May 06, 2011 12:48 pm

Re: Canonical URLS correct with CGBlog

Post by wmdvanzyl »

It seems that the canonical url doesn't have the page id in it. It only has the article id. So therefor it displays the article on the default blog detail page, which is exactly what i don't want.

Is there a way to append the page id to the canonical url in the template?
wmdvanzyl
Forum Members
Forum Members
Posts: 214
Joined: Fri May 06, 2011 12:48 pm

Re: Canonical URLS correct with CGBlog

Post by wmdvanzyl »

Code: Select all

{assign var='unique_identifier' value=$entry->id scope=global}
{*{$canonical_url = $entry->canonical|lower scope=global}*}
{$canonical_url = $canonical_url|cat:"/$unique_identifier/$page_id" scope=global}
I think this might be what i was after. I manually build the canonical url and include both the correct article id and page id. Now my canonical url reads:

Code: Select all

<link rel="canonical" href="https://modh.co.za/arch-blog/11/48/"/>
And that links to the correct article with the correct template applied. It doesn't have the article name at the end, but it doesn't seem to mind. WIll still figure out how to add that.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3484
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Canonical URLS correct with CGBlog

Post by velden »

Not having the article id might have negative impact regarding SEO (don't know for sure).

I'm not sure if this behavior (not including the return/page id) is by design or a bug. I could imagine why it is by design.

Does the detail action (template) have the $more_url (or similar) available? You could check by inserting the {get_template_vars} tag inside the detail template.
Post Reply

Return to “Modules/Add-Ons”