K
K
KASich2020-09-30 14:56:32
1C-Bitrix
KASich, 2020-09-30 14:56:32

How to redirect to the page of an infoblock element by its id?

The site has a trade catalog. Product links look like this: domain/catalog/section/product. Product links change from time to time. And I would like to set a link on a third-party portal and make it live as long as possible.

I would like to specify a link with the identifier of the infoblock element (product), for example, domain/links/id-123, and using it the user will be redirected to the actual product page.
Probably there is a ready-made solution for such redirection. But I couldn't find it.
Well, in theory, as I imagine, having the specified link with the id, it should not be difficult to redirect to the actual link.

Please let me know what is the solution here.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
KASich, 2020-09-30
@KASich

Solved the issue on my own. Created a separate page site.ru/redirect/ and added the code below. Now the site.ru/redirect/?id=123 link will redirect to the product with id 123. If no such product is found, it will redirect to site.ru/404/.
For IBLOCK_ID, instead of 17, set your infoblock id.

<?
$idItem = $_REQUEST['id'];
if (!empty($idItem)){
  $res = CIBlockElement::GetList(array(), array('ID'=>$idItem, 'IBLOCK_ID'=>'17'), false, false, array('DETAIL_PAGE_URL'));
  if ($arElement = $res->GetNext())
  {
     echo "<pre>"; print_r($arElement); echo "</pre>";
     LocalRedirect($arElement[DETAIL_PAGE_URL]);
  } else {
    LocalRedirect("/404/");
  }
} else {
  LocalRedirect("/404/");
}
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question