Simple Machines Community Forum

SMF Support => SMF 2.1.x Support => Topic started by: MobileCS on November 14, 2023, 11:37:28 AM

Title: Canonical URL Issue
Post by: MobileCS on November 14, 2023, 11:37:28 AM
I just noticed in Google search console that I have 2,500 (and climbing) URL's with "Alternate page with proper canonical tag" issues.

I'm seeing a weird issue concerning that. I have search engine friendly URL's turned on (it's been on for 15+ years, so I can't turn it off for SEO sake).

My URL is :
https://www.example.com/forum/index.php/topic,61952.0.html

If I am logged in, the canonical tag shows the same as above.

If I'm not logged in, the canonical tag shows as :
https://www.example.com/forum/index.php?topic=61952.0

Any idea why this is - and how I can fix it?
Title: Re: Canonical URL Issue
Post by: MobileCS on November 14, 2023, 02:45:31 PM
I'm not sure if it's the right way to fix it, but to stop the bleeding this seems to be working :

In Sources/Display.php :

Find:
$context['canonical_url'] = $scripturl . '?topic=' . $topic . '.' . ($can_show_all ? '0;all' : $context['start']);

Replace:
$context['canonical_url'] = $scripturl . '/topic,' . $topic . '.' . ($can_show_all ? '0/all.html' : $context['start'] . '.html');