Answer the question
In order to leave comments, you need to log in
How to make a redirect to the canonical URL for a product page in 1C-Bitrix?
Hello. Colleagues are faced with the task of making a redirect to the canonical url
What we have:
/catalog/cukaty/kumkvat/kumkvat-vyalenyy-laym/ the server answers 200
/catalog/cukaty/kumkvat-vyalenyy-laym/ and this page also answers 200 although there is an attribute that this home /catalog/cukaty/kumkvat/kumkvat-vyalenyy-laym/
Found on the net
Добавляем в result_modifier.php шаблона bitrix:catalog.element (Элемент каталога детально) следующий код:
$cp = $this->__component; // объект компонента if (is_object($cp)) { // добавим в arResult компонента поля $cp->arResult['RES_MOD']['CANONICAL_PAGE_URL'] = $arResult['CANONICAL_PAGE_URL']; $cp->arResult['RES_MOD']['SET_CANONICAL_URL'] = $arResult['ORIGINAL_PARAMETERS']['SET_CANONICAL_URL']; $cp->arResult['RES_MOD']['CURRENT_BASE_PAGE'] = $arResult['ORIGINAL_PARAMETERS']['CURRENT_BASE_PAGE']; $cp->SetResultCacheKeys(array('RES_MOD')); }
Добавляем там же в component_epilog.php
//определяем протокол define("SITE_SERVER_PROTOCOL", (CMain::IsHTTPS()) ? "https://" : "http://"); //создаем переменную со ссылкой на которой находится пользователь $thisUrl = SITE_SERVER_PROTOCOL . SITE_SERVER_NAME . $arResult['RES_MOD']['CURRENT_BASE_PAGE']; //проверяем стоит ли установка у компонента SET_CANONICAL_URL и не пустое ли значение у canonical if($arResult['RES_MOD']['SET_CANONICAL_URL'] == 'Y' && $arResult['RES_MOD']['CANONICAL_PAGE_URL'] != '') { //если ссылка не соответствует канонической if($arResult['RES_MOD']['CANONICAL_PAGE_URL'] != $thisUrl) { //делаем редирект LocalRedirect($arResult['RES_MOD']['CANONICAL_PAGE_URL']); } }
Answer the question
In order to leave comments, you need to log in
In general, I found a solution. It is necessary to register in the element.php file
"STRICT_SECTION_CHECK" => (isset($arParams["DETAIL_STRICT_SECTION_CHECK"]) ? $arParams["DETAIL_STRICT_SECTION_CHECK"] : ''),
path to the file domen.ru/bitrix/templates/your_theme/companents/bitrix/catalog/your_theme/element.php
So you then have REQUEST_URI and CANONICAL_PAGE_URL. Compare them and if different, redirect to component_epilog
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question