A
A
AndTheEnd2019-05-16 18:20:15
1C-Bitrix
AndTheEnd, 2019-05-16 18:20:15

How to form your link in the CNC in a complex component?

Good evening. Tell me please.
I use bitrix:news complex component.
The CNC was previously formed via /news/1234.html - where 1234 is the id of the news
. Moreover, the news with id 1234 is in the section section.
That is, the link template had the form
"section" => "#SECTION_CODE_PATH#/",
"detail" => "#ELEMENT_ID#.html",
Now we need to make sure that the new added news has a normal NC of the form
"section" => "#SECTION_CODE_PATH#/",
"detail" => "#SECTION_CODE_PATH#/"#ELEMENT_CODE#/",
But at the same time, the old news should remain with the old url - /news/1234.html
I don't know how to make new was a new url, and the old ones have an old one.
I wanted to use the SetUrlTemplates function
I wrote it in the result_modifier in news.list - but it didn't work - it gives a 404 error page.
Here is the code on the example of one ID

$rsElements = CIBlockElement::GetList(array(), array("ID" => 384857, "IBLOCK_ID" => 19), false, false, array("ID", "NAME", "DETAIL_PAGE_URL"));
$rsElements->SetUrlTemplates("/news/#SECTION_CODE_PATH#/#ELEMENT_CODE#.html");
$arElement = $rsElements->GetNext();
foreach($arResult["ITEMS"] as $key => $val){
  if($val["ID"] == $arElement["ID"]){
    $arResult["ITEMS"][$key]["DETAIL_PAGE_URL"] = $arElement["DETAIL_PAGE_URL"];
  }
}

That is, for this ID, the link is formed as I need, but during the transition it gives a 404 error. I mean, he doesn't care at all. For this component, the main thing is what the link template is when calling the component. That is, what goes into the $arParams array.
Tell me how I can make my own link template, please.
Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Gritsuk, 2019-05-16
@winer

No need to create duplicate pages. Do a redirect. If there are not many elements, then make a list and write redirects in htaccess. If there is a lot, then you can check the url on 404 for belonging to the old CNC template, if you find one, then do a redirect through LocalRedirect

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question