L
L
latishew2017-07-24 18:16:21
1C-Bitrix
latishew, 2017-07-24 18:16:21

Urlrewrite Bitrix. How to write a rule that excludes the character code of an element from a url?

An infoblock for cities has been launched. Those cities that are in the infoblock are available for selection.
Url when choosing a city is formed like /element_code/catalog/ but accordingly gives 404, how to redirect the request just to /catalog/ ? catalog is given as an example, there can be a great number of urls, but they will all start with element_code of the city.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Nikolaev, 2017-07-25
@latishew

If you really want to implement this (and if I understood you correctly), then you will need to do more than just that.
Step 1.
1) Create a page /catalog/index.php, display $_REQUEST on this page
2) Create a rule (taken from the example above, from the user Artyom Luchnikov )

array(
    "CONDITION" => "#^/([a-zA-Z0-9_-]*)/catalog/.*#",
    "RULE" => "city_code=\$1",
    "PATH" => "/catalog/index.php",
)

3) Check that when entering, for example, /moscow/catalog/, the page opens and the output array contains city_code=moscow
Step 2.
1) Copy the catalog (complex) component [for example, custom:catalog] into your space, move it to page /catalog/index.php
2) Add another shared variable in arComponentVariables to component.php - name it, for example CITY_CODE, write handlers in the body of the complex component that will "digest" the entered text and redirect to the necessary pages. In the sections.php template, output $_REQUEST
3) Check that when visiting, for example, /moscow/catalog/, the page opens and the output array contains city_code=moscow
Step 3.
1) In the rendered component (from the example above it is custom:catalog), make a handler for the specified city_code variable, which determines whether the specified city is in the infoblock
2) Check that everything works correctly
Well, the cherry on the cake, what if you made a choice infoblock, where the cities are taken into the component variables.

R
Roman Gritsuk, 2017-07-25
@winer

Isn't it easier to do instead of domain.ru/ city_code / like this: city_code .domain.ru ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question