Answer the question
In order to leave comments, you need to log in
How to add a canonical link to 1C Bitrix?
There is a site (Internet store), it has a lot of filtering options, and so is the division into pages (pagination) The site.ru/catalog/category/?PAGEN_1=2
question is, how can I implement a canonical link in the page header?
<link rel="canonical" href="site.ru/catalog/category/">
$arSection = CIblockSection::GetById($arResult["ID"])->GetNext();
$arResult['SECTION_PAGE_URL'] = $arSection['SECTION_PAGE_URL'];
$cp = $this->__component;
if (is_object($cp))
$cp->SetResultCacheKeys(array('SECTION_PAGE_URL'));
$APPLICATION->AddHeadString('<link href="http://'.SITE_SERVER_NAME.$arResult['SECTION_PAGE_URL'].'" rel="canonical" />',true);
$arElement = CIblockElement::GetById($arResult["ID"])->GetNext();
$arResult['DETAIL_PAGE_URL'] = $arElement['DETAIL_PAGE_URL'];
$cp = $this->__component;
if (is_object($cp))
$cp->SetResultCacheKeys(array('DETAIL_PAGE_URL'));
$APPLICATION->AddHeadString('<link href="http://'.SITE_SERVER_NAME.$arResult['DETAIL_PAGE_URL'].'" rel="canonical" />',true);
Answer the question
In order to leave comments, you need to log in
Alternatively, you can add the following code between the tags to the /bitrix/templates/theme_name/header.php file <head>...</head>
:
<link rel="canonical" href="<? echo $APPLICATION->GetCurDir(); ?>" />
$APPLICATION->SetPageProperty('canonical', $arResult["CANONICAL_PAGE_URL"]);
I struggled with this task for 4 hours today and before that the same amount, it didn’t work out for the categories according to your scheme, for those who also didn’t succeed, I still found a solution ( saitsozdanie.ru/bitrix/kak-ubrat-dubli -stranits-sa... - displays canonical on all pages at once, who may need it
But wouldn't such code dynamically change on different pages of the same product?
Let's say for a url with the address:
directory/manufacturer/name
there will be a canonical link = "catalog/manufacturer/name"
and for a
directory/country/name
there will be a canonical link ="catalog/country/name"
So what's the point of such canons?
After all, they should point all duplicates to one page, but in fact this does not happen.
Made a new module for 1C-Bitrix.
Allows you to beautifully process pagination, create pages like /page-2/, /stranica-2/ and at the same time comply with all Google recommendations for pagination, add rel=next/prev/canonical tags to pages with a page!
I hope it will be useful for someone!
I'd be grateful for your feedback and suggestions!
Module link: marketplace.1c-bitrix.ru/solutions/gorokhovdv.paging
I found a solution for inserting the canonical tag for all pages of the site:
- find the bitrix/modules/main/include/prolog.php file
- between the lines:
- put it in there
$url = $_SERVER['REQUEST_URI'];
$url = explode('?', $url);
$url = 'http://www.site.ru'.$url[0];
echo '<link rel="canonical" href="'.$url.'"/>';
AddHeadString is a bad idea. And if you already have another crookedly written module installed canonical through the same function. It is correct to do this:
In the admin panel, create the canonical property. We set it in the right places via $APPLICATION->SetPageProperty('canonical', 'link'); And the meaning of this delayed function is that only the last link in the code will be installed, and there can be any number of installations in any components and there will be no conflict.
in init.php we add deferred functions for output
function ShowCanonical() {
global $APPLICATION;
$APPLICATION->AddBufferContent('GetCanonical');
}
function GetCanonical(){
global $APPLICATION;
$val = $APPLICATION->GetProperty('canonical');
if ($val)
return '<link rel="canonical" href="' . $val . '">';
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question