Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

forum - issues with canonical urls on topic pages #4712

Closed
Jimmi08 opened this issue Mar 21, 2022 · 1 comment · Fixed by #4733
Closed

forum - issues with canonical urls on topic pages #4712

Jimmi08 opened this issue Mar 21, 2022 · 1 comment · Fixed by #4733
Assignees
Labels
type: enhancement An improvement or new feature request
Milestone

Comments

@Jimmi08
Copy link
Contributor

Jimmi08 commented Mar 21, 2022

Motivation

Get correct canonical urls for forum

first problem - too often changed URL

Now the topic URL is generated from title (it is OK), but with forum the topic title is changed too often, so its URL and then canonical URL is changed too.

Solution: use only version with ID without title part. Example:

		$config['topic'] = array(
			'regex'         => 'forum\/([^\/]*)\/([\d]*)(?:\/|-)([\w-]*)/?\??(.*)',
		//	'regex'			=> '^forum/(.*)/(\d*)(?:-|/)([\w-]*)/?\??(.*)',
			'sef'			=> 'forum/{forum_sef}/{thread_id}/{thread_sef}/',
			'redirect'		=> '{e_PLUGIN}forum/forum_viewtopic.php?id=$2&$4'
		);
- notice removed {thread_sef} from SEF URL
		$config['topic-canonical'] = array(
			'regex'         => 'forum\/([^\/]*)\/([\d]*)(?:\/|-)([\w-]*)/?\??(.*)',
		//	'regex'			=> '^forum/(.*)/(\d*)(?:-|/)([\w-]*)/?\??(.*)',
			'sef'			=> 'forum/{forum_sef}/{thread_id}/',
			'redirect'		=> '{e_PLUGIN}forum/forum_viewtopic.php?id=$2&$4'
		);   

second problem, pagination

Source: https://developers.google.com/search/blog/2013/04/5-common-mistakes-with-relcanonical#mistake-1:-rel=canonical-to-the-first-page-of-a-paginated-series

All one topic pages (no p parameter, ?p=2... etc) have the same canonical URL {this is not a problem only with forum)

I don't know how to solve this your way, but I was able to get needed result this way:

$page = (varset($_GET['p']) ? (int)$_GET['p'] : 1);
$thread->threadInfo['thread_page'] = $page;
e107::canonical('forum', 'topic-canonical', $thread->threadInfo); 
		$config['topic-canonical'] = array(
			'regex'         => 'forum\/([^\/]*)\/([\d]*)(?:\/|-)([\w-]*)/?\??(.*)',
		//	'regex'			=> '^forum/(.*)/(\d*)(?:-|/)([\w-]*)/?\??(.*)',
			'sef'			=> 'forum/{forum_sef}/{thread_id}/?p={thread_page}',
			'redirect'		=> '{e_PLUGIN}forum/forum_viewtopic.php?id=$2&$4'
		);   

Thanks

@Jimmi08 Jimmi08 added the type: enhancement An improvement or new feature request label Mar 21, 2022
@CaMer0n
Copy link
Member

CaMer0n commented Mar 30, 2022

@Jimmi08 Thanks. Looks like a suitable solution. PR welcome.

@CaMer0n CaMer0n added this to the e107 2.3.2 milestone Mar 30, 2022
CaMer0n added a commit that referenced this issue Apr 1, 2022
Fixes #4712 canonical URLs for paged forum topic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement An improvement or new feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants