-
Hello, i need help. News is displayed via a link The knowledge base is displayed via a different link In their sections they are filtered in the component settings, each with its own list. And everything seems fine, but if i insert slug from Knowledge base to News it working too and vice versa. and I don’t like it, because when i go to a page in this way, it ends up in Yandex Metrics and Google Analytics and they consider it a new page and after a while they say that it’s a duplicate. How to avoid this? So that the article related to the news section is available only in /blog/:slug and also with the knowledge base. kb.htm and blog.htm differ only in links (
|
Beta Was this translation helpful? Give feedback.
Replies: 11 comments 1 reply
-
I don't think there is a setting to avoid this, but you could apply some logic to the function onEnd()
{
$category = $this->post->categories->first();
// if ($category && $category->id === 2) {
if ($category && $category->name === 'news') {
Return Redirect::to(...);
}
} |
Beta Was this translation helpful? Give feedback.
-
Good idia, Only condition if for some reason it doesn’t work for me: echo($category); {"id":2,"name":"\u041d\u043e\u0432\u043e\u0441\u0442\u0438","slug":"news","code":null,"description":"","parent_id":null,"nest_left":1,"nest_right":6,"nest_depth":0,"created_at":"2022-12-17T16:43:19.000000Z","updated_at":"2023-09-20T16:25:50.000000Z","pivot":{"post_id":41,"category_id":2}} Maybe because of the multilingual. How will it be for "slug" it on all languages same "news" |
Beta Was this translation helpful? Give feedback.
-
Sorry, I should have writen |
Beta Was this translation helpful? Give feedback.
-
I updated my earlier code suggestion |
Beta Was this translation helpful? Give feedback.
-
I undestand, i change name to slug it more better for me and complete link where changing /support/kb/ to /blog/ if article in the news.
Is it possible to indicate somewhere 301 redirect in |
Beta Was this translation helpful? Give feedback.
-
The Category id is the only stable property in multi-lingual context (slug and name might differ in different locale for the same category) |
Beta Was this translation helpful? Give feedback.
-
Yes, I have slug in all languages, always in English. Thank you.
This is how it turned out, thank you for your help |
Beta Was this translation helpful? Give feedback.
-
@oim37 it would be safer to use this to generate the page URL:
Where "kb" is the basefilename of your knowledge page (e.g. support/kb) |
Beta Was this translation helpful? Give feedback.
-
Okay, that works too, then it will be like this:
On the news page i will do a reverse replacement if the article does not apply to it. |
Beta Was this translation helpful? Give feedback.
-
Make sure you actually USE function onEnd()
{
$category = $this->post->categories->first();
if ($category && $category->slug === 'news') {
$url = $this->controller->pageUrl('kb', ['slug' => $this->post->slug], false);
Return Redirect::to($url, 301);
}
} |
Beta Was this translation helpful? Give feedback.
-
Yes, I didn’t immediately understand all the magic of the code :) Wonderful |
Beta Was this translation helpful? Give feedback.
I don't think there is a setting to avoid this, but you could apply some logic to the
onEnd()
method of each page to avoid showing a post from each other (and maybe redirect to the other page)