Page 1 of 1
Google Canonical Errors
Posted: Thu Oct 17, 2024 6:53 am
by radact
Is there a way to stop Google crawls from creating so many canonical errors when indexing my site?
For a site that has <1500 pages, I get over 150,000 errors!
eg:
Code: Select all
https://www.anotherworld.com.au/shop/sound-and-audio?sort=rating&order=DESC&page=7&limit=50
https://www.anotherworld.com.au/shop/accessories-and-smart-watches?sort=rating&order=DESC&page=43
https://www.anotherworld.com.au/shop/software?page={page}
https://www.anotherworld.com.au/shop/merchandise?sort=pd.name&order=DESC&page=11&limit=25
https://www.anotherworld.com.au/shop/fan-splitter-cables?page=2&limit=20
As you can see, I've created SEO friendly URL's for products and categories, and properly formatted sitemaps, with various extensions that I've been able to find, but all that junk after the "?" is causing all these errors that I don't know where it's coming from or where Google is picking that up from! How do I make it just stick to the product names and categories and ignore all the extra data?
Thanks in advance!
OC 2.3.0.2
Re: Google Canonical Errors
Posted: Thu Oct 17, 2024 5:23 pm
by ADD Creative
There was a bug in 2.3.0.2 where some of the canonical tags were missing if the category URL had page in.
https://github.com/opencart/opencart/issues/4637
In catalog/controller/product/category.php find.
Code: Select all
if ($page == 1) {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'], true), 'canonical');
} elseif ($page == 2) {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'], true), 'prev');
} else {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'] . '&page='. ($page - 1), true), 'prev');
}
if ($limit && ceil($product_total / $limit) > $page) {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'] . '&page='. ($page + 1), true), 'next');
}
And replace with.
Code: Select all
if ($page == 1) {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id']), 'canonical');
} elseif ($page == 2) {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'] . '&page='. $page), 'canonical');
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id']), 'prev');
} else {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'] . '&page='. $page), 'canonical');
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'] . '&page='. ($page - 1)), 'prev');
}
if ($limit && ceil($product_total / $limit) > $page) {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'] . '&page='. ($page + 1)), 'next');
}
Re: Google Canonical Errors
Posted: Thu Oct 17, 2024 7:29 pm
by radact
So make a new XLM file in the vqmod/xml folder like this?:
Code: Select all
<modification>
<id>Header Logos</id>
<version>1.1</version>
<vqmver>2.6.1</vqmver>
<author></author>
<file name="catalog/controller/product/category.php">
<operation error="log">
<search position="replace">
<![CDATA[
if ($page == 1) {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'], true), 'canonical');
} elseif ($page == 2) {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'], true), 'prev');
} else {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'] . '&page='. ($page - 1), true), 'prev');
}
if ($limit && ceil($product_total / $limit) > $page) {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'] . '&page='. ($page + 1), true), 'next');
}
]]>
</search>
<add>
<![CDATA[
if ($page == 1) {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id']), 'canonical');
} elseif ($page == 2) {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'] . '&page='. $page), 'canonical');
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id']), 'prev');
} else {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'] . '&page='. $page), 'canonical');
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'] . '&page='. ($page - 1)), 'prev');
}
if ($limit && ceil($product_total / $limit) > $page) {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'] . '&page='. ($page + 1)), 'next');
}
]]>
</add>
</operation>
</file>
</modification>\
Re: Google Canonical Errors
Posted: Fri Oct 18, 2024 12:24 am
by ADD Creative
You can only replace single lines with vQmod. In which case, if you don't want to fix the core files, then you are probably better adding the following with a vQmod.
Code: Select all
if ($page > 1) {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'] . '&page='. $page), 'canonical');
}
Re: Google Canonical Errors
Posted: Fri Oct 18, 2024 6:02 am
by radact
Sorry, I'm confused now.
Can you please provide the vqmod code exactly so I can just cut n'paste it?
Re: Google Canonical Errors
Posted: Fri Oct 18, 2024 6:50 pm
by ADD Creative
Change the file section in your vQmod to.
Code: Select all
<file name="catalog/controller/product/category.php">
<operation error="log">
<search position="before"><![CDATA[
if ($page == 1) {
]]></search>
<add><![CDATA[
if ($page > 1) {
$this->document->addLink($this->url->link('product/category', 'path=' . $category_info['category_id'] . '&page='. $page), 'canonical');
}
]]></add>
</operation>
</file>
Re: Google Canonical Errors
Posted: Sat Oct 19, 2024 7:47 am
by radact
Thanks, let's see if it starts to make any improvement after Google does another crawl.
Re: Google Canonical Errors
Posted: Tue Nov 26, 2024 10:45 am
by radact
Is that all that is needed? Just that Page 1 reference? or the longer code you posted previously?
Some time has passed, but it doesn't seem to have made a difference to number of errors.
Re: Google Canonical Errors
Posted: Tue Nov 26, 2024 12:51 pm
by by mona
radact wrote: ↑Thu Oct 17, 2024 6:53 am
Is there a way to stop Google crawls from creating so many canonical errors when indexing my site?
I get over 150,000 errors!
eg:
Code: Select all
https://www.anotherworld.com.au/shop/sound-and-audio?sort=rating&order=DESC&page=7&limit=50
https://www.anotherworld.com.au/shop/accessories-and-smart-watches?sort=rating&order=DESC&page=43
https://www.anotherworld.com.au/shop/software?page={page}
https://www.anotherworld.com.au/shop/merchandise?sort=pd.name&order=DESC&page=11&limit=25
https://www.anotherworld.com.au/shop/fan-splitter-cables?page=2&limit=20
You say 150,000 canonical errors and paste 5. The 5 you have posted are all dealt with in robots.txt
Code: Select all
Disallow: /*?page=$
Disallow: /*&page=$
Disallow: /*?sort=
Disallow: /*&sort=
Disallow: /*?order=
Disallow: /*&order=
Disallow: /*?limit=
Disallow: /*&limit=
Re: Google Canonical Errors
Posted: Tue Nov 26, 2024 1:30 pm
by radact
Thanks Mona, appreciate that advice... I'll pop that in the robots.txt file and see what happens with the google indexes.
I'll update here once I've given it some time to reindex the site.
Re: Google Canonical Errors
Posted: Tue Nov 26, 2024 8:38 pm
by ADD Creative
radact wrote: ↑Tue Nov 26, 2024 10:45 am
Is that all that is needed? Just that Page 1 reference? or the longer code you posted previously?
Some time has passed, but it doesn't seem to have made a difference to number of errors.
Google can take months to re-crawl all the pages. You could inspect the URLs in Search Console and then Test Live URL. If all looks OK, you could then Validate Fix.